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

Direct link to selected row

2 Answers 34 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ning
Top achievements
Rank 1
Ning asked on 24 May 2012, 10:26 PM
Hi, I'm not sure if this is possible, but I'd like to provide a direct URL to a selected row in RadGrid so that users can access to the row by typing the URL in a browser.

Any pointers will be greatly appreciated.

ning

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 25 May 2012, 09:44 AM
Hello Ning,

Please check below code snippet.

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
            onprerender="RadGrid1_PreRender">
    <MasterTableView DataKeyNames=",ID" CommandItemDisplay="Top" Name="parent">
        <Columns>
                              <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
    <ClientSettings>
        <Selecting AllowRowSelect="true" />
    </ClientSettings>
</telerik:RadGrid>
protected void RadGrid1_PreRender(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["ID"]))
        {
            foreach (GridDataItem item in RadGrid1.MasterTableView.Items)
            {
                if (item.GetDataKeyValue("ID").ToString() == Request.QueryString["ID"].ToString())
                {
                    item.Selected = true;
                }
            }
        }
    }
 
 
 protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        DateTime dt = DateTime.Now;
 
        dynamic data = new[] {
                new { ID = 1, Name ="Name_1", customdate=dt,NO = 11.00,CustomerId="ALFKI",Stock=20,IsSysAdmin = true},
                new { ID = 2, Name = "Name2", customdate=dt,NO = 11.00,CustomerId="ALFKI2",Stock=30,IsSysAdmin = false},
                new { ID = 3, Name = "Name3", customdate=dt,NO = 11.00,CustomerId="ALFKI1",Stock=20,IsSysAdmin = true},
                new { ID = 4, Name = "Name4", customdate=dt,NO = 11.44,CustomerId="ALFKI",Stock=40,IsSysAdmin = true},
                new { ID = 55555, Name = "Name5", customdate=dt,NO = 10.4,CustomerId="ALFKI",Stock=20,IsSysAdmin = true}
            };
 
        RadGrid1.DataSource = data;
    }


Note : test with  YourPageName.aspx?ID=4
Thanks,
Jayesh Goyani
0
Ning
Top achievements
Rank 1
answered on 26 May 2012, 08:53 AM
Thanks a lot.

ning
Tags
Grid
Asked by
Ning
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Ning
Top achievements
Rank 1
Share this question
or