This is a migrated thread and some comments may be shown as answers.

Replacement for OnRowDataBound in Telerik RadGrid

10 Answers 1891 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Asad
Top achievements
Rank 1
Asad asked on 13 May 2009, 01:22 AM
Is they some RadGrid equivalent for ASP.Net GridView's OnRowDataBound event?
Please point me to some examples.


Thanks
Asad

10 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 May 2009, 03:29 AM
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.
0
drpcken
Top achievements
Rank 1
answered on 27 May 2009, 07:55 PM

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...
0
Princy
Top achievements
Rank 2
answered on 28 May 2009, 03:47 AM
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.
0
usman
Top achievements
Rank 1
answered on 01 Feb 2012, 10:49 PM
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];
 
        }
}


0
Princy
Top achievements
Rank 2
answered on 02 Feb 2012, 06:12 AM
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.
0
MANGESH
Top achievements
Rank 1
answered on 28 Feb 2013, 07:15 AM
 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;

                    }
0
Jeremy
Top achievements
Rank 1
answered on 16 Jul 2014, 09:49 PM

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;
}
}

0
Princy
Top achievements
Rank 2
answered on 17 Jul 2014, 03:54 AM
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
0
Jeremy
Top achievements
Rank 1
answered on 17 Jul 2014, 02:48 PM
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)
0
Jeremy
Top achievements
Rank 1
answered on 18 Jul 2014, 12:59 AM
I just figured it out.  It was simple enough.
currentEvent = (Event)e.Item.DataItem;

Thank you
Tags
Grid
Asked by
Asad
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
drpcken
Top achievements
Rank 1
usman
Top achievements
Rank 1
MANGESH
Top achievements
Rank 1
Jeremy
Top achievements
Rank 1
Share this question
or