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

expand NestedViewTemplate using querystring

2 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
tpowell
Top achievements
Rank 1
tpowell asked on 21 Jun 2010, 07:04 PM

I am using the radgrid to dispay quite a bit of data. To simplify the UI I have put the basic information into bound columns and given the user the option to expand each row using the nextviewtamplate to see a more detailed data much like this demo.


<telerik:RadGrid ID="grdTest" runat="server">  
<mastertableview>  
<Columns>  
...columns generated here  
</Columns>  
<NestedViewTemplate>  
...Detailed data form here  
</NestedViewTemplate>  
<mastertableview>  
</telerik:RadGrid>  


I am also referencing this data on other pages and am trying to put a link to this page with a query string parameter of what record to expand. However I cannot seem to find how to set the "expanded row" through the server side code.

Here is an example of what I am trying to do
protected void grdTest_ItemDataBound(object sender, GridItemEventArgs e) 
        { 
            if (e.Item.ItemType == GridItemType.Item || e.Item.ItemType == GridItemType.AlternatingItem) 
            { 
                if (!string.IsNullOrEmpty(Request.QueryString["id"])) 
                { 
                    string DBIndentity = DataBinder.Eval(e.Item.DataItem, "ID"string.Empty); 
                    string QueryStringIdentity = Request.QueryString["id"]; 
                    if (DBIndentity == QueryStringIdentity) 
                        e.Item.Expanded = true
                } 
            } 

Thanks in advance


2 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 24 Jun 2010, 12:38 PM
Hi tpowell,

Try using the PreRender event of the grid or the page instead:

protected void Page_PreRender(object sender, GridItemEventArgs e)
{
    if (!string.IsNullOrEmpty(Request.QueryString["id"]))
    {
        string QueryStringIdentity = Request.QueryString["id"];
 
        foreach (GridDataItem item in grdTest.MasterTableView.Items)
        {
            string DBIndentity = item.GetDataKeyValue("ID").ToString();
            if (DBIndentity == QueryStringIdentity)
                e.Item.Expanded = true;
        }
    }
}


Best wishes,
Veli
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
tpowell
Top achievements
Rank 1
answered on 24 Jun 2010, 04:36 PM
Thanks a ton, it worked like a charm.

I did have to make some modifications to your code but it works on the grid pre-render event, It however does not work on the page pre-render because the grid is not bound yet.

protected void grdTest_PreRender(object sender, EventArgs e) 
        { 
            if (!string.IsNullOrEmpty(Request.QueryString["id"])) 
            { 
                string QueryStringIdentity = Request.QueryString["id"]; 
                txtSearch.Text = grdTrainings.MasterTableView.Items.Count.ToString(); 
 
                foreach (GridDataItem item in grdTrainings.MasterTableView.Items) 
                { 
                    string DBIndentity = item.GetDataKeyValue("id").ToString(); 
                    if (DBIndentity == QueryStringIdentity) 
                        item.Expanded = true
                } 
            } 
        } 




Tags
Grid
Asked by
tpowell
Top achievements
Rank 1
Answers by
Veli
Telerik team
tpowell
Top achievements
Rank 1
Share this question
or