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

Nested grid issues

1 Answer 23 Views
Grid
This is a migrated thread and some comments may be shown as answers.
dingen
Top achievements
Rank 1
dingen asked on 25 Jan 2010, 10:27 AM
Hi

I am trying to :
a. create a header text for my OrderId column in my nested grid and the specific Employee, something like: "Orders for <Last Name> "
b. when i press the Go button I would like to display the EmployeeID?

thanks

D

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="NestedNew.aspx.vb" Inherits="NestedNew" %> 
 
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
<head id="Head1" runat="server"
</head> 
<body class="BODY"
    <form runat="server" id="mainForm" method="post"
    <telerik:RadScriptManager runat="server" ID="ScriptManager1"
    </telerik:RadScriptManager> 
    <!-- content start --> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"
        <AjaxSettings> 
            <telerik:AjaxSetting AjaxControlID="RadGrid1"
                <UpdatedControls> 
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" /> 
                </UpdatedControls> 
            </telerik:AjaxSetting> 
        </AjaxSettings> 
    </telerik:RadAjaxManager> 
    <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server" /> 
    <telerik:RadGrid ID="RadGrid1" OnPreRender="RadGrid1_PreRender" DataSourceID="SqlDataSource1" 
        runat="server" AutoGenerateColumns="False" AllowSorting="True" AllowMultiRowSelection="False" 
        AllowPaging="True" PageSize="5" GridLines="None" ShowGroupPanel="true"
        <PagerStyle Mode="NumericPages"></PagerStyle> 
        <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="EmployeeID" AllowMultiColumnSorting="True" 
            GroupLoadMode="Server"
            <NestedViewTemplate> 
                <asp:Label ID="label1" runat="server" Text='<%# Eval ("EmployeeID") %>'></asp:Label> 
                <asp:Label ID="label2" runat="server" Text='<%# Eval ("LastName") %>'></asp:Label> 
                <asp:Panel runat="server" ID="InnerContainer" CssClass="viewWrap" Visible="false"
                    <telerik:RadGrid runat="server" ID="OrdersGrid" DataSourceID="ObjectDataSource1" OnItemDataBound="onitemdatabound" 
                        OnItemCommand="onitemnested_command" ShowFooter="true" AllowSorting="true" EnableLinqExpressions="false"
                        <MasterTableView ShowHeader="true" AutoGenerateColumns="true" AllowPaging="true" 
                            DataKeyNames="OrderID" PageSize="7" HierarchyLoadMode="ServerOnDemand"
                            <Columns> 
                                <telerik:GridEditCommandColumn> 
                                </telerik:GridEditCommandColumn> 
                            </Columns> 
                            <EditFormSettings EditFormType="Template"
                                <FormTemplate> 
                                    <asp:Button ID="btninsert" runat="server" CommandName="PerformInsert" Text="go" /> 
                                </FormTemplate> 
                            </EditFormSettings> 
                        </MasterTableView> 
                    </telerik:RadGrid> 
                           <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetEmployeeid" 
                    TypeName="EmployeesODS"
                    <SelectParameters> 
                        <asp:ControlParameter ControlID="Label1" Name="empid" PropertyName="Text" 
                            Type="String" /> 
                    </SelectParameters> 
                </asp:ObjectDataSource> 
                    <asp:SqlDataSource ID="SqlDataSource3" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
                        ProviderName="System.Data.SqlClient" SelectCommand="SELECT OrderID, [Order Details].UnitPrice, Quantity, Discount, Products.ProductName FROM ([Order Details] LEFT JOIN Products on [Order Details].ProductID = Products.ProductID) where OrderID = @OrderID" 
                        runat="server"
                        <SelectParameters> 
                            <asp:SessionParameter Name="OrderID" SessionField="OrderID" Type="Int32" /> 
                        </SelectParameters> 
                    </asp:SqlDataSource> 
                </asp:Panel> 
          
            </NestedViewTemplate> 
            <Columns> 
                <telerik:GridBoundColumn SortExpression="FirstName" HeaderText="First Name" HeaderButtonType="TextButton" 
                    DataField="FirstName" UniqueName="FirstName"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn SortExpression="LastName" HeaderText="Last Name" HeaderButtonType="TextButton" 
                    DataField="LastName" UniqueName="LastName"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn SortExpression="Title" HeaderText="Title" HeaderButtonType="TextButton" 
                    DataField="Title" UniqueName="Title"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn SortExpression="BirthDate" DataFormatString="{0:MM/dd/yyyy}" 
                    HeaderText="Birth Date" HeaderButtonType="TextButton" DataField="BirthDate" UniqueName="BirthDate"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn SortExpression="City" HeaderText="City" HeaderButtonType="TextButton" 
                    DataField="City" UniqueName="City"
                </telerik:GridBoundColumn> 
                <telerik:GridBoundColumn SortExpression="Country" HeaderText="Country" HeaderButtonType="TextButton" 
                    DataField="Country" UniqueName="Country"
                </telerik:GridBoundColumn> 
            </Columns> 
        </MasterTableView> 
        <ClientSettings AllowDragToGroup="true" /> 
    </telerik:RadGrid> 
    <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>" 
        ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Employees" 
        runat="server"></asp:SqlDataSource> 
    <!-- content end --> 
    </form> 
</body> 
</html> 
 

Imports Telerik.Web.UI 
Imports System 
Imports System.Data 
Imports System.Data.SqlClient 
Imports System.Web.UI.WebControls 
Imports System.Configuration 
 
Partial Class NestedNew 
    Inherits System.Web.UI.Page 
 
    Protected Sub RadGrid1_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles RadGrid1.PreRender 
        If Not Page.IsPostBack Then 
            RadGrid1.MasterTableView.Items(0).Expanded = True 
            RadGrid1.MasterTableView.Items(0).ChildItem.FindControl("InnerContainer").Visible = True 
        End If 
    End Sub 
 
    Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand 
        If e.CommandName = RadGrid.ExpandCollapseCommandName Then 
 
            Session("EmployeeName") = DirectCast(source, Telerik.Web.UI.RadGrid).MasterTableView.Items(e.Item.ItemIndex)("LastName").Text 
            DirectCast(e.Item, GridDataItem).ChildItem.FindControl("InnerContainer").Visible = Not e.Item.Expanded 
        End If 
 
 
    End Sub 
 
    Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemCreated 
        If TypeOf e.Item Is GridNestedViewItem Then 
            e.Item.FindControl("InnerContainer").Visible = (DirectCast(e.Item, GridNestedViewItem)).ParentItem.Expanded 
        End If 
    End Sub 
 
 
    Public Shared Function GetDataTable(ByVal query As String) As DataTable 
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString 
        Dim conn As SqlConnection = New SqlConnection(ConnString) 
        Dim adapter As SqlDataAdapter = New SqlDataAdapter 
        adapter.SelectCommand = New SqlCommand(query, conn) 
        Dim table1 As New DataTable 
        conn.Open() 
        Try 
            adapter.Fill(table1) 
        Finally 
            conn.Close() 
        End Try 
        Return table1 
    End Function 
 
  
 
    Protected Sub onitemnested_command(ByVal source As Object, ByVal e As GridCommandEventArgs) 
        If e.CommandName = RadGrid1.PerformInsertCommandName Then 
            'write the employeeid 
            'Response.Write(label1.text) 
        End If 
    End Sub 
 
    Protected Sub onitemdatabound(ByVal sender As Object, ByVal e As GridItemEventArgs) 
        If e.Item.ItemType = GridItemType.Header And Not Session("EmployeeName") Is Nothing Then 
            Dim hd As GridHeaderItem = e.Item 
            hd("OrderID").Text = " the orders for " + Session("EmployeeName").ToString() 
 
 
        End If 
    End Sub 
End Class 
 


App_Code folder :

Imports Microsoft.VisualBasic 
 
Imports Telerik.Web.UI 
Imports System 
Imports System.Data 
Imports System.Data.SqlClient 
Imports System.Web.UI.WebControls 
Imports System.Configuration 
 
Public Class EmployeesODS 
    Public Shared Function GetEmployeeid(ByVal empid As StringAs ArrayList 
 
        Dim arr As New ArrayList 
 
 
        For Each dr As DataRow In GetDataTable("Select * from orders where employeeid='" + empid + "'").Rows 
 
            Dim emp As New Employee 
            emp.EmployeeID = dr("EmployeeID"
            emp.OrderId = dr("OrderID"
            arr.Add(emp) 
        Next 
 
        Return arr 
    End Function 
 
    Public Shared Function GetDataTable(ByVal query As StringAs DataTable 
        Dim ConnString As String = ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString 
        Dim conn As SqlConnection = New SqlConnection(ConnString) 
        Dim adapter As SqlDataAdapter = New SqlDataAdapter 
        adapter.SelectCommand = New SqlCommand(query, conn) 
        Dim table1 As New DataTable 
        conn.Open() 
        Try 
            adapter.Fill(table1) 
        Finally 
            conn.Close() 
        End Try 
        Return table1 
    End Function 
End Class 
 
 
Public Class Employee 
    Private _OrderId As String 
    Private _CompanyName As String 
    Private _EmployeeID As String 
 
 
 
    Public Property CompanyName() As String 
        Get 
            Return _CompanyName 
        End Get 
        Set(ByVal value As String
            _CompanyName = value 
        End Set 
    End Property 
 
    Public Property EmployeeID() As String 
        Get 
            Return _EmployeeID 
        End Get 
        Set(ByVal value As String
            _EmployeeID = value 
        End Set 
    End Property 
 
    Public Property OrderId() As String 
        Get 
            Return _OrderId 
        End Get 
        Set(ByVal value As String
            _OrderId = value 
        End Set 
    End Property 
 
 
End Class 
 

1 Answer, 1 is accepted

Sort by
0
Rosen
Telerik team
answered on 28 Jan 2010, 08:13 AM
Hi Dingen,

As you are using sorting in the inner grid you should set the text to the sort LinkButton. Similar to the following:

protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
   {
       if (e.Item is GridHeaderItem)
       {
           (((GridHeaderItem)e.Item)["OrderID"].Controls[0] as IButtonControl).Text = "some text";
       }
   }
 

Kind regards,
Rosen
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
dingen
Top achievements
Rank 1
Answers by
Rosen
Telerik team
Share this question
or