Item Value from GridDataItem

7 posts, 1 answers
  1. TadR
    TadR avatar
    18 posts
    Member since:
    Nov 2005

    Posted 10 May 2013 Link to this post

     

    In the ItemDataBound event we are no longer to retrieve the Item value using the following code and are getting the value of ' '

     

    If TypeOf e.Item Is GridDataItem Then
      
     Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem)
     
     Dim EAFID As String = NoNull(dataItem("row_ID").toString)

    This seems to be after a recent update of telerik versions as we were getting valid values.

    Any help or clues on why this method of access is not working?
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 10 May 2013 Link to this post

    Hello,

    Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
     
        If TypeOf e.Item Is GridDataItem Then
            Dim item As GridDataItem = TryCast(e.Item, GridDataItem)
            Dim strrow_ID As String = item("row_ID").Text ' for bound column

            Dim keyrow_ID As String = item.GetDataKeyValue("row_ID").ToString() ' using key value           
            Dim Labelrow_ID As String = TryCast(item.FindControl("Label1"), Label).Text ' Get label from ItemTemplate
          
        End If
    End Sub


    1. boundcolumn
    <telerik:GridBoundColumn DataField="row_ID" UniqueName="row_ID" HeaderText="row_ID">
                       </telerik:GridBoundColumn>

    2.datakey
    <MasterTableView  DataKeyNames="row_ID">

    3. lable in template column
    <telerik:GridTemplateColumn>
                           <ItemTemplate>
                               <asp:Label ID="Label1" runat="server" Text='<%# Eval("row_ID") %>'></asp:Label>
                           </ItemTemplate>
                       </telerik:GridTemplateColumn>


    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. TadR
    TadR avatar
    18 posts
    Member since:
    Nov 2005

    Posted 14 May 2013 Link to this post

    Hello Jayesh:
    Thank you for your response.
    However, I can't figure out how your response code is different than my original post. Am I missing something?

    If we use:

     
    Dim EAFID As String = NoNull(dataItem("row_ID").Text) gives us back a non breaking space as value

               
    Dim
    EAFID As String = NoNull(e.Item.DataItem("row_ID")) gives us back the correct value.

  5. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 14 May 2013 Link to this post

    Hello,

    I have shown three different way to get datafield in ItemDataBound event.

    if this code is not worked for you then please provide your code.

    Thanks,
    Jayesh Goyani
  6. Answer
    Vijay
    Vijay avatar
    6 posts
    Member since:
    Mar 2012

    Posted 14 May 2013 Link to this post

    TadR,

    I ran into a similar problem after upgrading to the Q1 2013 AJAX controls, but for me I only had issues accessing the data for columns that were set to visible="false". Not sure if the same is true in your case. I found this thread about a breaking change and was able to resolve my issue by using display="false" instead of using the visible="false".

    http://www.telerik.com/community/forums/aspnet-ajax/grid/breaking-change-hidden-column-cell-text-is-not-persisted-in-viewstate.aspx

    Hope this helps,

    Vijay
  7. Phil
    Phil avatar
    12 posts
    Member since:
    Jan 2011

    Posted 12 Jul 2013 Link to this post

    Another option if processing RadGrid_ColumnCreated is to set the set the .Visible=true and .Display=false. 

    protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)
     {
          
         if (e.Column.UniqueName == "ROWNO")
         {
             e.Column.HeaderText = "row no"//probably not necessary used for debugging
             e.Column.Visible = true;   //setting false results in null value
             e.Column.Display = false;   //set true to see values
         }
    }
  8. Josef Rogovsky
    Josef Rogovsky avatar
    144 posts
    Member since:
    Sep 2012

    Posted 12 Sep in reply to Vijay Link to this post

    Vijay, you just saved me a lot of frustration. Thank you!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017