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

Find id of the data item on radgrid1_ItemCreated

3 Answers 224 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Awadh .
Top achievements
Rank 1
Awadh . asked on 13 Nov 2009, 10:46 AM
Hi,

I need to find the id of the data items to be bound on radgrid1_ItemCreated.
Please refer to image attached with this post and code block below:


protected void gvManualOrder_ItemCreated(object sender, GridItemEventArgs e) 
        { 
             
                 
            if (e.Item is GridDataItem) 
            { 

I need to find the id on this item created event for all data being bind to the grid and pass those ids to database to validation & checks.
So what will be code for
ID ......


Thanks,
Awadh



3 Answers, 1 is accepted

Sort by
0
arnaud
Top achievements
Rank 1
answered on 13 Nov 2009, 11:10 AM
Hi,

You can access the radgrid Ids server side using :

 e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("id_table")

With the datakey defined inside the MasterTableView tag like that :

<MasterTableView CommandItemDisplay="Top" DataSourceID="SqlDataSource1" DataKeyNames="id_table" ....

Regards,
Arnaud Boiselle
0
Princy
Top achievements
Rank 2
answered on 13 Nov 2009, 11:19 AM
Hello Awadh,

Rather than using the ItemCreated event of the grid, you can access the items in the ItemDataBound event of the grid inorder to retrieve the ID values for each item. The ItemCreated event is fired before the data is bound and so the text would be rendered as '&nbsp;'. Here's an example:
c#:
protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            string id = item["IDColumnUniqueName"].Text;             
        } 
     } 

Thanks
Princy.
0
Awadh .
Top achievements
Rank 1
answered on 13 Nov 2009, 11:54 AM
Hi Princy

Thanks for your reply but I need to find the ids on item created event only because I need to pass the id to get some flag from database based on which will enable\disable the image buttons in item grid which you can see in code block below :

protected void gvManualOrder_ItemCreated(object sender, GridItemEventArgs e) 
        {                             
            if (e.Item is GridDataItem) 
            {                 
                GridDataItem item = (GridDataItem)e.Item; 
                ImageButton imgButton = (ImageButton)item["RecreateColumn"].Controls[0]; 
                ImageButton imgButton2 = (ImageButton)item["CancelColumnR"].Controls[0]; 
                imgButton.Enabled = false
                imgButton2.Enabled = false
After last line of this code, i need to find the ids here only to pass them as parameters. Hope I am clear in problem description..

So, please tell how to do this...These image buttons are same which are shown in screenshot in previous post & m also getting text  rendered as '&nbsp;'


My task is to enable\disable these image buttons before the grid bind on page load based on some flag coming from databse.


Thanks,
Awadh
Tags
Grid
Asked by
Awadh .
Top achievements
Rank 1
Answers by
arnaud
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Awadh .
Top achievements
Rank 1
Share this question
or