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

RadGrid How to capture the event when a user click the expand.

3 Answers 464 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Neil
Top achievements
Rank 1
Neil asked on 15 Oct 2010, 08:50 AM
Hi Im just new, Please give an example code on how can you capture the event when a user click the expand and get an item in the row which is clicked and then display it in the expanded panel.

Thanks!

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 15 Oct 2010, 10:16 AM
Hello Neil,

One option is using NestedViewTemplate for the grid to customizing the grid behavior. RadGrid gives you the ability to data bind the controls in a nested view template to a single item of a specified data source.

Demo
Documentation


-Shinu.
0
Neil
Top achievements
Rank 1
answered on 15 Oct 2010, 11:41 AM
Hi Shinu,
Thanks for the link and I've already saw the links that you provided.
But what I'm doing is a special case, to explain this:
1. The main radgrid is populated by data by using List<t> and i've no problem with that.
What I want to do is when I click the expand Iwant to get the value of a specific cell from the row where I click the expand  
and then use it to search another List<T> and then using the result I will populate the expanded panel.

I will gladly appreciate if you could give me an example of code that when I clicked the expand it will return a value(Get a value from that row that I expand).

Thanks thanks thanks!
0
Dimo
Telerik team
answered on 20 Oct 2010, 02:42 PM
Hello Neil,

You can do it in two ways, both are demonstrated below.

You need to define DataKeyNames for the corresponding tableview in order to use this tableview's GetDataKeyValue method of the data items.

"Column1" is a column's UniqueName.

<telerik:RadGrid
    ID="RadGrid1"
    runat="server"
    OnNeedDataSource="RadGrid_NeedDataSource" OnItemCommand="RadGrid1_ItemCommand">
    <MasterTableView DataKeyNames="Column1">
        <DetailTables>
            <telerik:GridTableView Width="100%" />
        </DetailTables>
    </MasterTableView>
</telerik:RadGrid>
 
<br /><br />
 
<asp:Label ID="Label1" runat="server" Text=" " />


C#

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.ExpandCollapseCommandName)
    {
        //Label1.Text = (e.Item as GridDataItem)["Column1"].Text;
        Label1.Text = (e.Item as GridDataItem).GetDataKeyValue("Column1").ToString();
    }
}


Kind regards,
Dimo
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
Tags
Grid
Asked by
Neil
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Neil
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or