Can someone give me some direction on how to get a handle to control, say an asp.net label, inside a templated column on a webgrid that was constructed at design time?
In a templated column you can have any content - for example you can start with just a placeholder and then add controls there programmatically in the InitializeRow event. For example:
<igtbl:TemplatedColumn> <CellTemplate> <asp:placeholder runat="server" ID="Placeholder1'> </CellTemplate></igtbl:TemplatedColumn>
and then in InitializeRow, you can do something similar to this (pseudo code, just for reference)
Thanks for this info but it's not exactly what I was looking for..at least I don't think.
I have an existing webgrid that has a templatedcolumn. In this TC there are 3 .net controls all wired up for data. This was done in design mode. I don't want to change this.
I need to figure out how to get access to one of these controls, the label, and apply a nowrap and/or width attribute to it.
Are you saying I can use the psuedocode part above to get a handle to this control?
I was trying to look into the cellitems object from initlayout or before databind to get at this control but the control count was 0. Maybe initrow is the place to do it.
I've taken a stab at this and come up empty. (Perhaps some of the Infragistics staff know something I don't. ;-)
The only thing I've come up with is that you can use Eval() to bind almost any property to a column in your datasource. If you really need different .NoWrap or .Length values in different rows, you could compute that as part of your data source.
Please let us know what you end up doing.
Thanks for all your help. Seems like this is a little more complicated than I originally thought. Putting this on the back burner for now...If someone from Infragistics responds I'll take it up again.
What he typed is how you get a handle on the control in a cell.
First, you need to grab a handle of the TemplatedColumn from the Grid.
TemplateColumn oCol = (TemplateColumn)grdFilterAddress.Rows[iX].Cells.FromKey("Key").Column;
Then you need to get the "cell" itself.
CellItem oCell = (CellItem)oCol.CellItems[iX];
Then get the control (in this case a DropDownList):
DropDownList cboDropDown = (DropDownList)oCell.FindControl("cboDropDown");
Thanks.
Sean
hey did you get a response from the development team on how to get a reference to a control inside a templated column?
I ran into this problem and I thought you could help. Thanks.
Hello,
This is the UltraWebGrid forum, you can ask questions about WebDataGrid here:
http://forums.infragistics.com/forums/196.aspx
Unfortunately I too was not able to find a way to find control in a templated column in InitializeRow using FindControl. I tried almost everything I could think of -- without any success. I will ask the development team about a solution for this problem.
Meanwhile there are two workaround that you can use
1) Databinding expressions directly in the ASPX
<asp:Label ID="lblTest" runat="server" Text='<%# Eval("ProductName") %>'
2) Obtain a reference to the Label using its own OnInit event
<ig:TemplateDataField Key="testColumn"> <ItemTemplate> <asp:Label ID="lblTest" runat="server" OnInit="label_Init"> </asp:Label> </ItemTemplate> </ig:TemplateDataField> protected void label_Init(object sender, EventArgs e) { ((Label)(sender)).Text = "test"; }
Hope this helps.
Has anyone found a way how to do this in WebDataGrid?