Вопрос

I have telerik grid and I want to get the value of GridBoundColumn in OnItemCreated event

here is my code

<telerik:RadGrid OnNeedDataSource="RGrid_NeedDataSource"  AutoGenerateColumns="false" OnItemCommand="RadGrid1_ItemCommand" OnItemDataBound="rad_RowDataBound" OnItemCreated="RadGrid1_ItemCreated" ID="radgrid" runat="server" AllowPaging="true" PagerStyle-AlwaysVisible="true" >
    <MasterTableView SkinID="SunSet">
     <Columns>
....
 <telerik:GridBoundColumn  FilterControlWidth="60" DataField="Status" HeaderText="Status" UniqueName="Status" HeaderStyle-Width="250px"></telerik:GridBoundColumn>
...
</AllColisgTags>

and In my C# code

 protected void RadGrid1_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {

//Here I want to get the value of Status in string I have trid find controls 
e.Item.FindControl("Status");//Did not work
}
}
Это было полезно?

Решение 2

try this

<telerik:GridTemplateColumn  FilterControlWidth="60" DataField="Status" HeaderText="Status" UniqueName="Status" HeaderStyle-Width="250px">
 <asp:Label ID="Status" Text='<%# Bind("Status") %>' runat="server"></asp:Label>
</telerik:GridTemplateColumn>

C#

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            Label lbl = (Label)item["TemplateColumn"].FindControl("Status");
            string iss = lbl.Text;

        }
}

Другие советы

Please try with the below code snippet.

ASPX

<telerik:GridBoundColumn  FilterControlWidth="60" DataField="Status" HeaderText="Status" UniqueName="Status" HeaderStyle-Width="250px"></telerik:GridBoundColumn>

ASPX.CS

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
 if (e.Item is GridDataItem)
        {
            GridDataItem item = (GridDataItem)e.Item;
            string iss = item["Status"].Text; // Status is column Uniquename
        }
}

Note : We can not get/access value of any column/row in ItemCreated event. You have to use ItemDataBound or prerender event for same.

Please also check below links for more information.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top