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?
The answer is, yes it's possible and you're pretty much there. The "Container" in the template is an instance of the "CellItem" class (http://help.infragistics.com/Help/NetAdvantage/NET/2007.3/CLR2.0/html/Infragistics2.WebUI.UltraWebGrid.v7.3~Infragistics.WebUI.UltraWebGrid.CellItem_members.html) which has a "Cell" property that can be used to walk up the chain in the grid. In your case, if you want to get to another cell, use Container.Cell.Row.Cells[index].Value
Hope this helps. I'll be forwarding this post on to our Docs team and pursue getting a topic written up on this as well.
-Tony
Hey Tony, Thanks a lot for the answer. Is it possible for me to access the row info in the code behing in the command method. I would rather not have to pass the whole row in some kind of concatenated list?
What I ended up doing in one case was this:
<igtxt:WebImageButton ID="btnView" runat="server"
CommandArgument="<%# Container.Value%>" CssClass="pointer"
OnCommand="btnView_Command" ToolTip="View this Message">
<Image Url="~/Image/icon/ico_view.gif" />
string Val = e.CommandArgument.ToString();
Session["RefreshNotes"] = "Yes";
This is kind of a backwards way to access the row, as is passing multiplte cell values in the command argument.
I would like to be able to just pass in a pointer to the row, similar to how a row click event works??
This example does not work, but I would like to be able to do something like this:
<igtbl:TemplatedColumn AllowRowFiltering="false" BaseColumnName="RecId" Key="RecId" Width="25px">
CommandArgument="<%# Container.Cell.Row%>" CssClass="pointer"
I get a cast / convert error for the e.CommandArgument. Maybe I just need to make a conversion to make this work, but I don't think this method was meant to work like this???
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: ";