C # Teletext cell cell value from template column

I have a column with a grid template like this (to save time and space, I just put a column):

<telerik:GridTemplateColumn HeaderText="Id" Reorderable="true" SortExpression="Id" UniqueName="Id" DataField="Id"> <ItemTemplate> <asp:Label ID="lblId" runat="server" Text='<%# Eval("Id") %>' /> </ItemTemplate> <EditItemTemplate> <telerik:RadTextBox ID="txbId" Width="50px" runat="server" TextMode="SingleLine" Text='<%# Bind("Id") %>' /> </EditItemTemplate> <ItemStyle VerticalAlign="Top" /> </telerik:GridTemplateColumn> 

And I want in the PreRender event to extract the value of this column

 protected void RadGrid1_PreRender(object sender, System.EventArgs e) { //string selectedItem = ((GridDataItem)RadGrid1.SelectedItems[0])["Id"].Text; foreach (GridDataItem item in RadGrid1.Items) { //not working string k = item["Id"].Text;// is empty string string key = (item["Id"].TemplateControl.FindControl("lblId") as RadTextBox).Text;// null pointer } 

Any idea how to fix this?

thanks a lot.

+4
source share
3 answers

It seems that the solution is quite simple, answered on the telerik forum:

 foreach (GridDataItem item in grdHeader.EditItems) { // if in editing mode GridEditableItem edititem = (GridEditableItem)item.EditFormItem; RadTextBox txtHeaderName = (RadTextBox)edititem.FindControl("txbId"); //otherwise Label lbl= (Label)edititem.FindControl("lblId"); string id = lbl.Text; } 
+2
source

I could be wrong (since I am not very familiar with the Telerik control set), but as a rule, data binding events do not occur until the PreRender control event occurs. You will have to use the DataBind sooner or move your logic later into the page life cycle .

0
source

Try

 foreach (GridDataItem item in RadGrid1.Items) { if(item.ItemType == GridItemType.Item || item.ItemType == GridItemType.AlternatingItem) { string k = item["Id"].Text;// is empty string ... 
0
source

All Articles