473,231 Members | 1,984 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Sorting Problem in Nested Datagrid

Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error:
NullReferenceException error
Any help........pls urgent

================================================== =======
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm3.aspx.vb" Inherits="TestDatagrids.WebForm3"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<p><asp:datagrid id="DataGrid1" runat="server" OnItemCommand="DataGrid1_ItemCommand" Height="128px"
BorderStyle="Dotted" BorderColor="Silver" Width="904px" DataMember="ParentTable" AllowSorting="True"
BackColor="White" HorizontalAlign="Left" Font-Name="Verdana" Font-Size="9pt" AutoGenerateColumns="False"
ItemStyle-VerticalAlign="Top" AllowPaging="True" Font-Names="Verdana" CellPadding="2">
<FooterStyle BackColor="Silver"></FooterStyle>
<ItemStyle BorderColor="Transparent" VerticalAlign="Top"></ItemStyle>
<HeaderStyle Font-Size="10px" Font-Bold="True" HorizontalAlign="Center" BackColor="Silver"></HeaderStyle>
<asp:ImageButton id="ImageButton1" runat="server" ImageUrl="Images/Plus.GIF" CommandName="Expanded"></asp:ImageButton>
<asp:BoundColumn DataField="au_id" SortExpression="au_id" HeaderText="au_id" FooterText="au_id"></asp:BoundColumn>
<asp:BoundColumn DataField="au_lname" SortExpression="au_lname" HeaderText="au_lname" FooterText="au_lname"></asp:BoundColumn>
<asp:BoundColumn DataField="au_fname" SortExpression="au_fname" HeaderText="au_fname" FooterText="au_fname"></asp:BoundColumn>
<asp:BoundColumn DataField="city" SortExpression="city" HeaderText="city" FooterText="city"></asp:BoundColumn>
<HeaderStyle ForeColor="White" BorderStyle="Dotted" BorderColor="White" BackColor="White"></HeaderStyle>
<ItemStyle ForeColor="White" BorderStyle="Dotted" BorderColor="White" BackColor="White"></ItemStyle>
<asp:PlaceHolder id="Expanded" runat="server" Visible="False">
<TD width="9"></TD>
<TD colspan="4">
<asp:DataGrid id=Datagrid3 DataSource='<%# Container.DataItem.CreateChildView("ParentTable_Ch ildTable") %>' runat="server" OnItemCommand="DataGrid3_ItemCommand" AllowSorting="True" BackColor="Thistle" Font-Name="Verdana" Font-Size="8pt" AutoGenerateColumns="false" ItemStyle-VerticalAlign="Top" AllowPaging="True" CellPadding="2" GridLines="Both" ShowFooter="false" EnableViewState="true" OnSortCommand="DataGrid3_SortCommand" OnItemDataBound="Datagrid3_ItemDatabound" >
<AlternatingItemStyle BackColor="#E0E0E0"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" HorizontalAlign="Center" ForeColor="White" BackColor="DimGray"></HeaderStyle>
<asp:BoundColumn DataField="Childau_ID" SortExpression="Childau_ID" HeaderText="au_id" FooterText="au_id"></asp:BoundColumn>
<asp:BoundColumn DataField="title_id" SortExpression="title_id" HeaderText="title_id" FooterText="title_id"></asp:BoundColumn>
<asp:BoundColumn DataField="au_ord" SortExpression="au_ord" HeaderText="au_ord" FooterText="au_ord"></asp:BoundColumn>
<asp:BoundColumn DataField="title" SortExpression="title" HeaderText="title" FooterText="title"></asp:BoundColumn>
<asp:BoundColumn DataField="type" SortExpression="type" HeaderText="type" FooterText="type"></asp:BoundColumn>
<asp:BoundColumn DataField="notes" SortExpression="notes" HeaderText="notes" FooterText="notes"></asp:BoundColumn>
<asp:BoundColumn DataField="pubdate" SortExpression="pubdate" HeaderText="pubdate" FooterText="pubdate"></asp:BoundColumn>
<FooterStyle ForeColor="White" BorderStyle="Dotted" BorderColor="White" BackColor="White"></FooterStyle>
<PagerStyle BorderColor="Transparent" BackColor="Transparent" Mode="NumericPages"></PagerStyle>

Imports System.Data.SqlClient
Public Class WebForm3
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.StrConn = New System.Data.SqlClient.SqlConnection

End Sub
Protected WithEvents DataGrid1 As System.Web.UI.WebControls.DataGrid

'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
Strconn.ConnectionString = ConfigurationSettings.AppSettings.Item("ConnectMe" )
End Sub

#End Region
#Region "Global Variables"
Dim dbas As New DataAccess
Dim sortdtset As New DataSet
'Dim CFn As New Class_Fn
Dim dgUniqueID As String
Dim dt As New Data.DataTable
Dim msql As String
'Public DdlMstrList As Data.DataTable
'Public DdlPCP As Data.DataTable
Dim StrConn As SqlConnection
Public ds As New DataSet
#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
End If

End Sub

Private Sub BindData(Optional ByVal astrSort As String = "", Optional ByVal astrSort1 As String = "")

Dim lstrSQL As String
Dim ldtbParentTable As New DataTable
Dim ldtbChildTable As New DataTable

Dim lobjDataRelation As DataRelation
Dim lintPageSize As Int32
Dim llngTotalRec As Int32
'Dim conn
Dim dcAuthor
Dim daAuthor
Dim dcTitle
Dim daTitle

'//Prepare the connection object


'Query to get Customer Details - Parent Query

lstrSQL = "select au_id,au_lname,au_fname,city from authors"


dcAuthor = New SqlCommand(lstrSQL, StrConn)
daAuthor = New SqlDataAdapter(dcAuthor)
ldtbParentTable.TableName = "ParentTable"

'Query to get Order Details - Child Query

lstrSQL = "select t.au_id as Childau_ID,t.title_id,t.au_ord,a.title,a.type,a.no tes,a.pubdate from titleauthor t inner join titles a on t.title_id=a.title_id"

dcTitle = New SqlCommand(lstrSQL, StrConn)
daTitle = New SqlDataAdapter(dcTitle)
ldtbChildTable.TableName = "ChildTable"
Session("dtchild") = ldtbChildTable
'Add both these tables to the dataset

'//Create relation and this relation name should be used on CreateChildView
Dim dr As New DataRelation("ParentTable_ChildTable", ldtbParentTable.Columns("au_id"), ldtbChildTable.Columns("Childau_ID"), False)
dr.Nested = True

Catch ex As Exception
ds = Nothing
End Try

'Set the datasource to parent datagrid

DataGrid1.DataSource = ds
Session("dtsetI") = ds
Catch exc As Exception
Exit Sub
End Try
End Sub
Public Sub DataGrid3_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs)

End Sub
Public Sub DataGrid3_ItemCommand(ByVal source As Object, _
ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs )
Dim dgTemp As New DataGrid
dgTemp = CType(source, DataGrid)
dgUniqueID = dgTemp.UniqueID

End Sub

Public Sub DataGrid1_ItemCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles DataGrid1.ItemCommand
Dim strSQL As String

Select Case e.CommandName

Case "Expanded" '//Case for expanding the + sign on Parent grid to show the child grid

Dim img As ImageButton
Dim exp As PlaceHolder

'Before expanding, collapse previously opened child grid
Dim dgItem As DataGridItem

'For Each dgItem In DataGrid1.Items
' If dgItem.ItemIndex = Session("PrevItemIndex") And dgItem.ItemIndex <> e.Item.ItemIndex Then
img = e.Item.Cells(0).FindControl("ImageButton1")
If img.ImageUrl = "Images/Plus.GIF" Then
img.ImageUrl = "Images/Minus.GIF"
img.ImageUrl = "Images/Plus.GIF"
End If

exp = e.Item.Cells(5).FindControl("Expanded")
exp.Visible = Not exp.Visible

' Exit For
' End If

'img = e.Item.Cells(0).FindControl("ImageButton1")
'If img.ImageUrl = "Images/Plus.gif" Then
' img.ImageUrl = "Images/Minus.gif"
' img.ImageUrl = "Images/Plus.gif"
'End If

'exp = e.Item.Cells(2).FindControl("Expanded")
'exp.Visible = Not exp.Visible
'Session("PrevItemIndex") = e.Item.ItemIndex 'Store the ItemIndex in session variable
'Session("au_ID") = e.Item.Cells(1).Text 'Store the auID
' DataGrid1.SelectedIndex = e.Item.ItemIndex
End Select
End Sub

Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles DataGrid1.SortCommand

sortdtset = Session("dtsetI")
Dim dview As New DataTable
dview = sortdtset.Tables(0)
Dim dview1 As New DataView
dview1.Table = dview
If gridSortOrder = "" Then
gridSortOrder = "ASC"
DataGrid1.ToolTip = "Ascending Sort"
ElseIf gridSortOrder = "ASC" Then
gridSortOrder = "DESC"
DataGrid1.ToolTip = "Decending Sort"
ElseIf gridSortOrder = "DESC" Then
gridSortOrder = "ASC"
DataGrid1.ToolTip = "Ascending Sort"
End If
dview1.Sort = e.SortExpression & " " & gridSortOrder
DataGrid1.DataSource = dview1
'GroupColumn(dgriddoctor, 0)
Catch ex As Exception
End Try
End Sub

Public Sub DataGrid3_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEvent Args)
'Dim sortdtset1 As New DataSet
Dim dview2 As New Data.DataTable
sortdtset = Session("dtsetI")
Dim dgTemp As New DataGrid
dgTemp = CType(source, DataGrid)


dview2 = sortdtset.Tables(1)

Dim dview3 As New DataView
dview3.Table = dview2
dgTemp.DataSource = dview3
'dview2.TableName = "dview3"
If gridSortOrder = "" Then
gridSortOrder = "ASC"
dgTemp.ToolTip = "Ascending Sort"
ElseIf gridSortOrder = "ASC" Then
gridSortOrder = "DESC"
dgTemp.ToolTip = "Decending Sort"
ElseIf gridSortOrder = "DESC" Then
gridSortOrder = "ASC"
dgTemp.ToolTip = "Ascending Sort"
End If
dview3.Sort = e.SortExpression & " " & gridSortOrder
dgTemp.DataSource = dview3.Table.DataSet
dgUniqueID = dgTemp.UniqueID
Dim a As String
a = dgTemp.Items(0).Cells(0).Text()
'GroupColumn(dgriddoctor, 0)
'Catch ex As Exception
'End Try

End Sub
Public Property gridSortOrder() As String
Dim oSortOrder As Object = ViewState("gridSortOrder")
If oSortOrder Is Nothing Then
Return "ASC"
End If
gridSortOrder = oSortOrder
End Get
Set(ByVal Value As String)
ViewState("gridSortOrder") = Value
End Set
End Property

Private Sub DataGrid1_PageIndexChanged(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridPageChangedEvent Args) Handles DataGrid1.PageIndexChanged
DataGrid1.CurrentPageIndex = e.NewPageIndex

End Sub
End Class
================================================== ============
Aug 21 '07 #1
0 2033

Sign in to post your reply or Sign up for a free account.

Similar topics

by: Gareth Gale | last post by:
I'm trying to implement a way of allowing a user to sort a HTML table via Javascript on the client. I've seen lots of samples where single column sorting (asc or desc) is shown, but I'd like nested...
by: DelphiBlue | last post by:
I have a Nested Datagrid that is using a data relations to tie the parent child datagrids together. All is working well with the display but I am having some issues trying to sort the child...
by: melanieab | last post by:
Hi, I'm programatically sorting in a datagrid. When a column header is clicked, the sort happens twice for some reason, making it looks like it only sorts in descending order. I can tell it...
by: Dheeraj Verma via DotNetMonster.com | last post by:
Hi all, I have a asp data grid under which i have another datagrid which is my user control and is autogenerated.Now I am not able to implement sorting in my inner datagrid eventhough I have...
by: Dheeraj Verma via DotNetMonster.com | last post by:
Hi all, I have a asp data grid under which i have another datagrid which is my user control and is autogenerated.Now I am not able to implement sorting in my inner datagrid eventhough I have...
by: Matthew Curiale | last post by:
I am creating an app that lists clients of a company for management of different attributes for that company. The first page is a listing of the companies currently in the database. I have my...
by: DKC | last post by:
Hi, Using VB.NET. I have a datagrid having a strongly typed array of objects as its data source. The data from the array of objects is displayed by means of a table style, which is fine, but...
by: simchajoy2000 | last post by:
I thought the only thing I had to do to disable column sorting in VB.NET was to set datagrid.AllowSorting = False. Unfortunately this has never worked for me. I discovered another set of code...
by: Chris | last post by:
I've been searching all over and think I am close, but keep getting the error "Index out of range" when trying to reference a nested datagrid when an OnEditCommand event is raised. When the...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.