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

[Solved] get the item using datakeyvalue outside radgrid event

3 Answers 195 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Prathibarani
Top achievements
Rank 1
Prathibarani asked on 06 May 2013, 05:07 PM
Hi,

I am trying to get an item in Radgrid using datakeyvalue like this:
I have done on aspx page like this:
<MasterTableView DataKeyNames="ID">

<

 

 

telerik:GridBoundColumn AllowFiltering="False" DataField="ID" Groupable="False" HeaderText="ID" ReadOnly="True" Reorderable="False" ShowFilterIcon="False" UniqueName="ID" Display="false">

 

 

 

<ColumnValidationSettings>

 

 

 

<ModelErrorMessage Text="" />

 

 

 

</ColumnValidationSettings>

 

 

 

</telerik:GridBoundColumn>

 


</MasterTableView>

There are many other columns bound.
int IDValue = 85;

GridDataItem item = RadGrid1.MasterTableView.FindItemByKeyValue("ID", IDValue);

This returns item as null. When I check RadGrid1.Items.Count. It is returning number of rows in the grid in immediate window. So, to trouble shoot, I found out which item has ID as 85 and then in immediate window in asp.net I did this:

RadGrid1.Items[25].Cells[6].Text

This one is returning me the value. That means there is an item with ID value as 85 in the grid

why is Master table code is not working.

Thanks,
Prathiba.

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 May 2013, 04:38 AM
Hi,

You can access the datakeyvalue as shown below.
c#
protected void Button2_Click1(object sender, EventArgs e)
{
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
        {
            string value = item.GetDataKeyValue("ID").ToString();
         }
}

Thanks,
Shinu
0
Prathibarani
Top achievements
Rank 1
answered on 07 May 2013, 02:26 PM
Thanks Shinu for response. I prefer not to loop thru all the rows for getting 1 row with particular ID value. I don't need value of ID column in each row. I need a row that has particular ID value.


Thanks,
PK
0
Shinu
Top achievements
Rank 2
answered on 08 May 2013, 05:32 AM
Hi,

If you want to access the datakeyvalue from external button click event, you need to loop through the rows and retrieve its value.

Thanks,
Shinu
Tags
Grid
Asked by
Prathibarani
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Prathibarani
Top achievements
Rank 1
Share this question
or