How can I find control which it is in the WebGrid's cell by c#? There is page code at below:
<igtbl:TemplatedColumn> <HeaderStyle HorizontalAlign="center" /> <HeaderTemplate> <asp:CheckBox ID="cbAll" runat="server" onclick="SelectAll(this.checked,this.id);" /> </HeaderTemplate> <CellStyle HorizontalAlign="center" /> <CellTemplate> <asp:CheckBox ID="cbSingle" runat="server" onclick="SelectSingle(this.checked,this.id);" /> </CellTemplate></igtbl:TemplatedColumn>
I wish find which control's id is cbSingle in WebGrid's function that named DataBound, how can I do?
Hello,
The following code demonstrates how to use the FindControl method to find a control in the cell of a WebGrid's TemplatedColumn:
// Cast the Column to a Templated Column object TemplatedColumn tc = (TemplatedColumn)UltraWebGrid1.Bands(0).Columns(0); // Create a Templated Column CellItem object for each row CellItem item = (CellItem)tc.CellItems(e.Row.BandIndex); // Create a CheckBox object to find the Control CheckBox chkbx = (CheckBox)item.FindControl("cbSingle"); Once you have the object, then implement the rest of your code. Please let me know if this is helpful.
Sincerely,Mike D.
Good ways to get a reference to a control in a templated column in a particular row are illustrated in the following forum post:http://forums.infragistics.com/forums/p/26392/97012.aspx#97012
Thank you answer. But your way doesn't right. I already find solution. Only I find one row, I can find any asp.net control which in TemplatedColumn.
not sure what you are asking, but I think this C# snippet may be what you need.
Label lblCol1 = ((Label)e.Row.Cells.FromKey("Col1")).FindControl("lblCol1");
that casts lblCol1 on the server side to the label inside the column.
this was taken from an InitializeRow event, which is why I used e.Row
If you are not using it in a row event, you will need GridName.Rows[rownum].Cell.FromKey.....
Please see below aspx page code:
<igtbl:TemplatedColumn Key="Col1" >
<CellTemplate>
<asp:Image ID="imgCol1" runat="server" />
<asp:Label ID="lblCol1" runat="server" />
</CellTemplate>
</igtbl:TemplatedColumn>
<igtbl:TemplatedColumn Key="Col2" >
<asp:Image ID="imgCol2" runat="server" />
<asp:Label ID="lblCol2" runat="server" />
How can I find "lblCol2" control that is in Key is Col2 by "imgCol1" control that is in Key is Col1 when I am in ItemCommand?