How to get column value from ItemTemplate

5 posts, 0 answers
  1. johnson lim
    johnson lim avatar
    72 posts
    Member since:
    Feb 2010

    Posted 23 Nov 2011 Link to this post

    Hi ,my code is as below:
    <ajax:GridTemplateColumn UniqueName="CompNo" HeaderText="CompNo" SortExpression="CompNo" HeaderStyle-Width="70px" ItemStyle-VerticalAlign="Top">
        <ItemTemplate>
            <%#DataBinder.Eval(Container.DataItem, "CompNo")%> 
        </ItemTemplate>
    </ajax:GridTemplateColumn>

    Does anyone how to get the value from the column?
    Help Please!!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 23 Nov 2011 Link to this post

    Hello Johnson,

    Try the following code snippet.
    C#:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
     if (e.Item is GridDataItem)
     {
      GridDataItem item = (GridDataItem)e.Item;
      string s = ((DataRowView)e.Item.DataItem)["CompNo"].ToString();
     }
    }

    -Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Bill Togkas
    Bill Togkas avatar
    18 posts
    Member since:
    Mar 2010

    Posted 16 Feb 2012 Link to this post

    Is there any other option because the GridDataItem does not have any 
    DataItem declared
  5. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 16 Feb 2012 Link to this post

    Hello,

    I am not quite sure about your requirement. Try the following the code to get the column value from the ItemTemplate.
    Aspx:
    <telerik:GridTemplateColumn>  
     <ItemTemplate>
       <%# Eval("EmployeeID")%>
     </ItemTemplate>
    </telerik:GridTemplateColumn>

    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
     if (e.Item is GridDataItem)
     {
      string EmployeeID = ((DataRowView)e.Item.DataItem)["EmployeeID"].ToString();
     }
    }

    -Shinu.
  6. Bill Togkas
    Bill Togkas avatar
    18 posts
    Member since:
    Mar 2010

    Posted 17 Feb 2012 Link to this post

    Tnx Shinu that seems fine
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017