我有一个像这样定义的grid-template-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>
我希望在PreRender事件中提取此列的值
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
}
知道怎么解决吗?
多谢.
最佳答案 似乎解决方案相当简单,在telerik论坛上回复:
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;
}