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

[Solved] Pass ID to another grid when paging.

5 Answers 224 Views
Grid
This is a migrated thread and some comments may be shown as answers.
L
Top achievements
Rank 1
L asked on 07 Dec 2009, 07:28 AM
hi

I have 2 grids in one page. For example, Order Grid and Order Detail Grid

The Order Grid has paging enabled.

How do i pass the orderid on the Order Grid to Order Detail Grid and i page from page 1 to page 2 and so on? Thanks

So that when click page 2 on the Order Grid, it should reflect Order Detail of that OrderID on page 2. Thanks

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 Dec 2009, 09:59 AM
Helo,

Here is the demo that shows how to use dependant grids.
Grid / Master/Detail Grids

You can attach ItemCommand event to 'Order grid' and set the SqlDatasource (which bound to 'Order detail' grid) SelectParameter from code behind, according to the page changed, and then Rebind the Order Details grid.

-Shinu.
0
L
Top achievements
Rank 1
answered on 07 Dec 2009, 04:26 PM
hi

The Grid / Master/Detail Grids is not suitable for me cause I am having 1 record per page due to too much information on the customer. Anyway here is my shorten code:

 <telerik:GridTemplateColumn DataField="Order_ID"
           HeaderText="Order Histories"
            SortExpression="Order_ID" UniqueName="Order_ID">
           <ItemTemplate>
           
              <table cellpadding="0" cellspacing="0" class="style1">
        <tr>
            <td class="tdcolor">
                Customer Name:</td>
            <td>
                 <asp:Label ID="Label2" runat="server"
                    Text='<%# Eval("Customer_Name") %>'></asp:Label> -  <asp:Label ID="Label11" runat="server"
                    Text='<%# Eval("Customer_ID") %>'></asp:Label></td>
             <td>
                 <asp:Label ID="Label3" runat="server"
                    Text='<%# Eval("Customer_Address") %>'></asp:Label>
            </td>
        </tr>
       <tr>
            <td colspan="4">
                 <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="Select"
                    Text="View Order History"></asp:LinkButton></td>
        </tr>
    </table>
        </ItemTemplate>
        </telerik:GridTemplateColumn>

As you can see, i am using ItemTemplate to layout my grid. So, effectively, i can only show 1 customer per page due to overwhelming info about customer.

Now, I have link button with a CommandName="Select". How should go about doing it so that when i click View Order History linkbutton, i want the orderid to pass it to a session variable?

I tried using this but it is not working:

Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
        If e.CommandName = "Select" Then
            Dim selectedRow As GridDataItem = DirectCast(e.Item, GridDataItem)
                     Session("orderid") = selectedRow("Order_ID").Text.ToString()
        End If
 
End Sub


Thanks
0
Yavor
Telerik team
answered on 10 Dec 2009, 01:29 PM
Hi L,

 Your general syntax for accessing the item:

Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
        If e.CommandName = "Select" Then
            Dim selectedRow As GridDataItem = DirectCast(e.Item, GridDataItem)
                     Session("orderid") = selectedRow("Order_ID").Text.ToString()
        End If 
End Sub

is correct. If this is a standard cell, the value should be retrieved normally. However, if this cell hosts other controls in it, you can try locating them via the .Controls collection for the cell, or via the .FindControl() method of the cell. One of these approaches will get the proper value.


Best wishes,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
L
Top achievements
Rank 1
answered on 23 Dec 2009, 01:42 PM
hi

It is not working. When i did a breakpoint at the Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand, it is empty or nothing.

It seems that  <asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="false" CommandName="Select"
                    Text="View Order History"></asp:LinkButton> is not able to get the Order_ID field. How should I solve this? Thanks
0
Accepted
Veli
Telerik team
answered on 28 Dec 2009, 03:57 PM
Hi L,

You can add Order_ID to the  DataKeyNames collection of the MasterTableView and then get the key value in RadGrid's ItemCommand event:

Dim selectedRow As GridDataItem = DirectCast(e.Item, GridDataItem)
Session("orderid") = selectedRow.GetDataKeyValue("Order_ID")


Best wishes,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
L
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
L
Top achievements
Rank 1
Yavor
Telerik team
Veli
Telerik team
Share this question
or