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

Get RadGrid Row Count and DataKey In PreRender

1 Answer 403 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Perry
Top achievements
Rank 1
Perry asked on 17 Jan 2019, 03:49 PM

I have a RadGrid with 700,000 rows.  I do not bind the RadGrid until the user runs a search function to filter the data.  If the filtered data returns only 1 row I would like to skip showing the the Radgrid and just open a web page that would show the information for the single record.  I can not figure out how to the get the DataKey for that single record.

I am thinking the logical place would be the PreRender event.  to get a row count in the prerender and if that row count was 1 then get the datakey and redirect to my edit page with the the data key as my QueryString. 

This is far as I can get with the code:

int count = RadGrid1.Items.Count;
            if (count == 1)
            {
                string a ="How can I get the datakey value for this 1 row ?"
            }

1 Answer, 1 is accepted

Sort by
0
Perry
Top achievements
Rank 1
answered on 17 Jan 2019, 04:21 PM
I was able
int count = RadGrid1.Items.Count;
            if (count == 1)
            {
                string ID = RadGrid1.MasterTableView.Items[0].GetDataKeyValue("ID").ToString();
                Response.Redirect("~\\Add-EditRecord.aspx?ID=" + ID, false);
            }
to figure this out here is the code that works for me
Tags
Grid
Asked by
Perry
Top achievements
Rank 1
Answers by
Perry
Top achievements
Rank 1
Share this question
or