I was searching through the old forums trying to figure out how to bind a value to a Templated Column that is using an Web Image Button. For the most part, I saw unanswered posts from a long time ago. I finally found the answer, so I will post it:
This is what the column code looks like for the grid in the aspx page:
<igtbl:TemplatedColumn Key="RecId" BaseColumnName="RecId" AllowRowFiltering="false" Width="25px">
<CellTemplate>
<igtxt:WebImageButton ID="btnLink" runat="server"
CssClass="pointer"
OnCommand="btnLink_Command" CommandArgument="<%# Container.Value%>" ToolTip="Edit Security">
<Appearance>
<Image Url="~/Image/icon/ico_edit.gif" />
</Appearance>
</igtxt:WebImageButton>
</CellTemplate>
</igtbl:TemplatedColumn>
Here is the code behind button command event:
{
}
I do have one other question though, is it possible to send the data for more than one column or the entire row using the code above?
Hi Tony,
I have figured this out already. All I did was add another method call OnLoad so it loads the modal when the first page loads up and when I click on the linkbutton for the first time, the modal loads and all of my data is being passed on to the modal and if I change the data, it passes it back to the parent page. So now it works great. I also posted my solution on my original post just in case if anyone wants to do something similar.
Thanks again for looking into my issue.
HS2
How is your template set up? Are you binding the LinkUrl of the link button to your modal dialog url declaratively? It sounds like you may be trying to change the value based on the click event - which will indeed force you to click the button twice. Here are my suggestions -
Bind the property of the linkbutton to the modal dialog url declaratively (in the aspx).
-or-
In your itemcommand event, register a startupscript which will open a new window with the specified link.
-Tony
Hi,
I was just wondering, I am using an asp.net LinkButton inside Template Column and when I click on this link button it opens up a modal for me which it does but the only thing is that, it does not open up on the first click but only opens up on the second click, it seems like on the first click the link button does not get initialize to the path for the modal but on the second it click it does. If I tried to open the modal again, it only requires one click. Now, if I were to go to the second row, I have to click it twice and the first click would initialize the path to the modal then on the second click, it will open the modal on the first. I tried to initialize it on the Page_Load, InitializeLayout, InitializeRow but it can't find the LinkButton1 control ID that I have named it on the HMTL side. It can find it on the LinkButton1_Click event. I thought I ask my question here because I see above that you use LiteralControl to pass in your javascript functions to open up the pop up. Which I do use and I just need to know how to initialize it for the first time when the page load up so I don't have to click on my link button twice to on each row in order for it to load.
Thanks very much in advance!
As you found out, the CommandArgument needs to be a string. Using the PrimaryKey field, or the row index is a good way to be able to access the data through the CommandArgument. If you use the PrimaryKey field, you can query your backend from the CommandEvent handler rather than having to work through the grid. Either way is just as good.
OK, I finally figured it out. Just use Container.Cell.Row.Index.
Here is the example:
<igtbl:TemplatedColumn AllowRowFiltering="false" Width="25px">
<igtxt:WebImageButton ID="btnEdit" runat="server" CommandArgument="<%# Container.Cell.Row.Index%>" CssClass="pointer" OnCommand="btnEdit_Command" ToolTip="Edit Security">
try
UltraGridRow currentRow = UltraWebGrid1.Rows[Val];
int ClientRecID = Convert.ToInt32(currentRow.Cells.FromKey("ClientRecID").Text);
ErrorMsg = "UltraWebGrid1_Click Error: ";