Replacement for OnRowDataBound in Telerik RadGrid

11 posts, 0 answers
  1. Asad
    Asad avatar
    4 posts
    Member since:
    May 2009

    Posted 12 May 2009 Link to this post

    Is they some RadGrid equivalent for ASP.Net GridView's OnRowDataBound event?
    Please point me to some examples.


    Thanks
    Asad
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 12 May 2009 Link to this post

    Hello Asad,

    You can use the ItemDataBound event of the grid which replaces the RowDataBound event of the GridView(Asp.Net).
    c#:
    protected void RadGrid2_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item is GridDataItem)// to access a row 
            { 
                GridDataItem item = (GridDataItem)e.Item; 
                 
                
            } 
        } 

    Thanks
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. drpcken
    drpcken avatar
    36 posts
    Member since:
    Feb 2007

    Posted 27 May 2009 Link to this post


    protected
     void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 
        if (e.Row.RowType == DataControlRowType.DataRow) 
        { 
             //code here 
        } 


    I'm trying to do the same thing.  I need to access the RowDataBound event but it looks like the RadGrid doesn't have one.  For example I want to accomplish the above in my RadGrid.  I need to get the RowType... how can I do that without the RowDataBound event?

    I want to do the following using the RadGrid  http://www.codeproject.com/KB/webforms/EditGridviewCells.aspx

    If i have to abandon the RadGrid in order to do so then its unfortunate...
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 27 May 2009 Link to this post

    Hello drpcken,

    The ItemDataBound event in RadGrid resembles the RowDataBound event in GridView. GridDataItem represents the row collection in RadGrid which resembles the RowType - DataRow.
    aspx:
     <telerik:RadGrid ID="RadGrid1" runat="server" OnItemDataBound="RadGrid1_ItemDataBound" >       
            <MasterTableView DataSourceID="SqlDataSource1"

    c#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) // similar to RowDataBound event in GridView 
        {  
            if (e.Item is GridDataItem)// gets the row collection  
            {  
                GridDataItem item = (GridDataItem)e.Item;  
                  
                 
            }  
        }  

    Also refer to the following document for better understanding :
    Accessing cells and rows

    Thanks
    Princy.
  6. usman
    usman avatar
    34 posts
    Member since:
    Jun 2010

    Posted 01 Feb 2012 Link to this post

    Please I want to asssign command argument a value here
    http://www.telerik.com/community/forums/aspnet-ajax/grid/assigning-grid-view-hyper-link-button-command-argument.aspx#1971209 

    I tried it on eval and also on code behind but not working 


        
    protected void RadGrid1_ItemDataBound1(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)// to access a row
            {
                GridDataItem item = (GridDataItem)e.Item;
                GridButtonColumn aa = (GridButtonColumn)item.Cells[0];
     
            }
    }


  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 02 Feb 2012 Link to this post

    Hello,

    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;
           LinkButton LinkButton1= (LinkButton)item["buttoncol"].Controls[0];
           LinkButton1.CommandArgument = DataBinder.Eval(e.Item.DataItem, "MemberID") as String;
           }
       }

    Thanks,
    Princy.
  8. MANGESH
    MANGESH avatar
    1 posts
    Member since:
    Feb 2013

    Posted 28 Feb 2013 Link to this post

     if (e.Item is GridDataItem)
                    {
                        GridDataItem dataItem = (GridDataItem)e.Item;
                        string strDocumentMasterId = dataItem.GetDataKeyValue("datakeyName").ToString();
                      
                            Image img = (Image)dataItem.FindControl("img1");
                            img.Visible = false;

                        }
  9. Jeremy
    Jeremy avatar
    29 posts
    Member since:
    Apr 2014

    Posted 16 Jul 2014 Link to this post

    So once you have GridviewItem Item, how do you get the databound item? 
    In an asp gridview it's as simple as casting e.Row.DataItem as the item it was bound to...apparently it's different with

    RadGrids.protected void Page_Load(object sender, EventArgs e)
    {
    List<MyObject> obj1 = new List<Event>();
    obj1.GetMyObjects();
    RadGrid1.DataSource = obj1;
    RadGrid1.DataBind();
    }
     
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    {
    if (e.Item is GridDataItem)
    {
    //GridDataItem item = (GridDataItem)e.Item;
    Event currentEvent = new Event();
    currentEvent = (Event)e.Item;
    }
    }

  10. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Jul 2014 in reply to Jeremy Link to this post

    Hi Jeremy,

    I guess you want to know how to access the rows in ItemDatabound event, please take a look at the following article on Accessing Cells and Rows. If this doesn't help, please elaborate on your requirement.

    Thanks,
    Princy
  11. Jeremy
    Jeremy avatar
    29 posts
    Member since:
    Apr 2014

    Posted 17 Jul 2014 in reply to Princy Link to this post

    Well like I said in my post, I'm not looking to get a GridDataItem, I'm looking to get a single instance of the object that is bound to the RadGrid.  The example you give shows how to get columns bound to the grid using GridDataItem but I need the actual instance of the object.  With an asp Gridview you can get the object by casting the row's DataItem to that object because GridViewRowEventArgs e.Row.DataItem is of type Object and is easily cast back to the original object it came from:
    protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            EventObject currEvent = new EventObject();
            currEvent = ((EventObj)e.Row.DataItem);
        }
    }

    While GridItemEventArgs e.Item is of type GridDataItem which can't be cast back to the original object.  I need more than just piecemeal columns from the RadGrid row, I need the whole object back like you can with an asp Gridview.  Is it possible with a RadGrid?

    (By the way, sorry if I'm threadjacking.  It seemed to make sense here because it's used in context of the _ItemDataBound event)
  12. Jeremy
    Jeremy avatar
    29 posts
    Member since:
    Apr 2014

    Posted 17 Jul 2014 in reply to Jeremy Link to this post

    I just figured it out.  It was simple enough.
    currentEvent = (Event)e.Item.DataItem;

    Thank you
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017