473,545 Members | 2,543 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sorting Problem in Nested Datagrid

9 New Member
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:
NullReferenceEx ception error
Any help........pls urgent

=============== =============== =============== ============
<%@ Page Language="vb" AutoEventWireup ="false" Codebehind="Web Form3.aspx.vb" Inherits="TestD atagrids.WebFor m3"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>WebForm3 </title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="Visual Basic .NET 7.1" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5" name="vs_target Schema">
</HEAD>
<body MS_POSITIONING= "GridLayout ">
<form id="Form1" method="post" runat="server">
<p><asp:datagri d id="DataGrid1" runat="server" OnItemCommand=" DataGrid1_ItemC ommand" Height="128px"
BorderStyle="Do tted" BorderColor="Si lver" Width="904px" DataMember="Par entTable" AllowSorting="T rue"
BackColor="Whit e" HorizontalAlign ="Left" Font-Name="Verdana" Font-Size="9pt" AutoGenerateCol umns="False"
ItemStyle-VerticalAlign=" Top" AllowPaging="Tr ue" Font-Names="Verdana" CellPadding="2" >
<FooterStyle BackColor="Silv er"></FooterStyle>
<ItemStyle BorderColor="Tr ansparent" VerticalAlign=" Top"></ItemStyle>
<HeaderStyle Font-Size="10px" Font-Bold="True" HorizontalAlign ="Center" BackColor="Silv er"></HeaderStyle>
<Columns>
<asp:TemplateCo lumn>
<ItemTemplate >
<asp:ImageButto n id="ImageButton 1" runat="server" ImageUrl="Image s/Plus.GIF" CommandName="Ex panded"></asp:ImageButton >
</ItemTemplate>
</asp:TemplateCol umn>
<asp:BoundColum n DataField="au_i d" SortExpression= "au_id" HeaderText="au_ id" FooterText="au_ id"></asp:BoundColumn >
<asp:BoundColum n DataField="au_l name" SortExpression= "au_lname" HeaderText="au_ lname" FooterText="au_ lname"></asp:BoundColumn >
<asp:BoundColum n DataField="au_f name" SortExpression= "au_fname" HeaderText="au_ fname" FooterText="au_ fname"></asp:BoundColumn >
<asp:BoundColum n DataField="city " SortExpression= "city" HeaderText="cit y" FooterText="cit y"></asp:BoundColumn >
<asp:TemplateCo lumn>
<HeaderStyle ForeColor="Whit e" BorderStyle="Do tted" BorderColor="Wh ite" BackColor="Whit e"></HeaderStyle>
<ItemStyle ForeColor="Whit e" BorderStyle="Do tted" BorderColor="Wh ite" BackColor="Whit e"></ItemStyle>
<ItemTemplate >
<asp:PlaceHolde r id="Expanded" runat="server" Visible="False" >
<TR>
<TD width="9"></TD>
<TD colspan="4">
<asp:DataGrid id=Datagrid3 DataSource='<%# Container.DataI tem.CreateChild View("ParentTab le_ChildTable") %>' runat="server" OnItemCommand=" DataGrid3_ItemC ommand" AllowSorting="T rue" BackColor="This tle" Font-Name="Verdana" Font-Size="8pt" AutoGenerateCol umns="false" ItemStyle-VerticalAlign=" Top" AllowPaging="Tr ue" CellPadding="2" GridLines="Both " ShowFooter="fal se" EnableViewState ="true" OnSortCommand=" DataGrid3_SortC ommand" OnItemDataBound ="Datagrid3_Ite mDatabound" >
<AlternatingIte mStyle BackColor="#E0E 0E0"></AlternatingItem Style>
<HeaderStyle Font-Bold="True" HorizontalAlign ="Center" ForeColor="Whit e" BackColor="DimG ray"></HeaderStyle>
<Columns>
<asp:BoundColum n DataField="Chil dau_ID" SortExpression= "Childau_ID " HeaderText="au_ id" FooterText="au_ id"></asp:BoundColumn >
<asp:BoundColum n DataField="titl e_id" SortExpression= "title_id" HeaderText="tit le_id" FooterText="tit le_id"></asp:BoundColumn >
<asp:BoundColum n DataField="au_o rd" SortExpression= "au_ord" HeaderText="au_ ord" FooterText="au_ ord"></asp:BoundColumn >
<asp:BoundColum n DataField="titl e" SortExpression= "title" HeaderText="tit le" FooterText="tit le"></asp:BoundColumn >
<asp:BoundColum n DataField="type " SortExpression= "type" HeaderText="typ e" FooterText="typ e"></asp:BoundColumn >
<asp:BoundColum n DataField="note s" SortExpression= "notes" HeaderText="not es" FooterText="not es"></asp:BoundColumn >
<asp:BoundColum n DataField="pubd ate" SortExpression= "pubdate" HeaderText="pub date" FooterText="pub date"></asp:BoundColumn >
</Columns>
</asp:DataGrid>
</asp:PlaceHolder >
</ItemTemplate>
<FooterStyle ForeColor="Whit e" BorderStyle="Do tted" BorderColor="Wh ite" BackColor="Whit e"></FooterStyle>
</asp:TemplateCol umn>
</Columns>
<PagerStyle BorderColor="Tr ansparent" BackColor="Tran sparent" Mode="NumericPa ges"></PagerStyle>
</asp:datagrid></p>
</form>
<P></P>
</FORM>
</body>
</HTML>

========
Imports System.Data.Sql Client
Public Class WebForm3
Inherits System.Web.UI.P age

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnos tics.DebuggerSt epThrough()> Private Sub InitializeCompo nent()
Me.StrConn = New System.Data.Sql Client.SqlConne ction

End Sub
Protected WithEvents DataGrid1 As System.Web.UI.W ebControls.Data Grid

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

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
Strconn.Connect ionString = ConfigurationSe ttings.AppSetti ngs.Item("Conne ctMe")
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.EventArg s) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
BindData()
End If

End Sub

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

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

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

Try
'//Prepare the connection object

StrConn.Open()


'Query to get Customer Details - Parent Query


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

Try

dcAuthor = New SqlCommand(lstr SQL, StrConn)
daAuthor = New SqlDataAdapter( dcAuthor)
daAuthor.Fill(l dtbParentTable)
ldtbParentTable .TableName = "ParentTabl e"

'Query to get Order Details - Child Query


lstrSQL = "select t.au_id as Childau_ID,t.ti tle_id,t.au_ord ,a.title,a.type ,a.notes,a.pubd ate from titleauthor t inner join titles a on t.title_id=a.ti tle_id"

dcTitle = New SqlCommand(lstr SQL, StrConn)
daTitle = New SqlDataAdapter( dcTitle)
daTitle.Fill(ld tbChildTable)
ldtbChildTable. TableName = "ChildTable "
Session("dtchil d") = ldtbChildTable
'Add both these tables to the dataset
ds.Tables.Add(l dtbParentTable)
ds.Tables.Add(l dtbChildTable)

'//Create relation and this relation name should be used on CreateChildView
Dim dr As New DataRelation("P arentTable_Chil dTable", ldtbParentTable .Columns("au_id "), ldtbChildTable. Columns("Childa u_ID"), False)
dr.Nested = True
ds.Relations.Ad d(dr)


Catch ex As Exception
ds = Nothing
End Try

'Set the datasource to parent datagrid

DataGrid1.DataS ource = ds
DataGrid1.DataB ind()
Session("dtsetI ") = ds
Catch exc As Exception
'LogMessage(exc )
Exit Sub
Finally
dcAuthor.Dispos e()
daAuthor.Dispos e()
dcTitle.Dispose ()
daTitle.Dispose ()
ds.Dispose()
StrConn.Close()
End Try
End Sub
Public Sub DataGrid3_ItemD ataBound(ByVal sender As Object, ByVal e As System.Web.UI.W ebControls.Data GridItemEventAr gs)

End Sub
Public Sub DataGrid3_ItemC ommand(ByVal source As Object, _
ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs)
Dim dgTemp As New DataGrid
dgTemp = CType(source, DataGrid)
dgUniqueID = dgTemp.UniqueID
BindData()

End Sub

Public Sub DataGrid1_ItemC ommand(ByVal source As Object, ByVal e As System.Web.UI.W ebControls.Data GridCommandEven tArgs) Handles DataGrid1.ItemC ommand
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.ItemInde x = Session("PrevIt emIndex") And dgItem.ItemInde x <> e.Item.ItemInde x Then
img = e.Item.Cells(0) .FindControl("I mageButton1")
If img.ImageUrl = "Images/Plus.GIF" Then
img.ImageUrl = "Images/Minus.GIF"
Else
img.ImageUrl = "Images/Plus.GIF"
End If

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

' Exit For
' End If
'Next

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

'exp = e.Item.Cells(2) .FindControl("E xpanded")
'exp.Visible = Not exp.Visible
'Session("PrevI temIndex") = e.Item.ItemInde x 'Store the ItemIndex in session variable
'Session("au_ID ") = e.Item.Cells(1) .Text 'Store the auID
' DataGrid1.Selec tedIndex = e.Item.ItemInde x
End Select
End Sub

Private Sub DataGrid1_SortC ommand(ByVal source As Object, ByVal e As System.Web.UI.W ebControls.Data GridSortCommand EventArgs) Handles DataGrid1.SortC ommand

sortdtset = Session("dtsetI ")
Try
Dim dview As New DataTable
dview = sortdtset.Table s(0)
Dim dview1 As New DataView
dview1.Table = dview
If gridSortOrder = "" Then
gridSortOrder = "ASC"
DataGrid1.ToolT ip = "Ascending Sort"
ElseIf gridSortOrder = "ASC" Then
gridSortOrder = "DESC"
DataGrid1.ToolT ip = "Decending Sort"
ElseIf gridSortOrder = "DESC" Then
gridSortOrder = "ASC"
DataGrid1.ToolT ip = "Ascending Sort"
End If
dview1.Sort = e.SortExpressio n & " " & gridSortOrder
DataGrid1.DataS ource = dview1
DataGrid1.DataB ind()
'GroupColumn(dg riddoctor, 0)
sortdtset.Dispo se()
Catch ex As Exception
'PageError(ex)
End Try
End Sub

Public Sub DataGrid3_SortC ommand(ByVal source As Object, ByVal e As System.Web.UI.W ebControls.Data GridSortCommand EventArgs)
'Dim sortdtset1 As New DataSet
Dim dview2 As New Data.DataTable
sortdtset = Session("dtsetI ")
Dim dgTemp As New DataGrid
dgTemp = CType(source, DataGrid)

'Try

dview2 = sortdtset.Table s(1)

Dim dview3 As New DataView
dview3.Table = dview2
dgTemp.DataSour ce = dview3
dgTemp.DataBind ()
'dview2.TableNa me = "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.SortExpressio n & " " & gridSortOrder
dgTemp.DataSour ce = dview3.Table.Da taSet
dgUniqueID = dgTemp.UniqueID
Dim a As String
a = dgTemp.Items(0) .Cells(0).Text( )
dgTemp.DataBind ()
'GroupColumn(dg riddoctor, 0)
sortdtset.Dispo se()
'Catch ex As Exception
'PageError(ex)
'End Try


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

Private Sub DataGrid1_PageI ndexChanged(ByV al source As Object, ByVal e As System.Web.UI.W ebControls.Data GridPageChanged EventArgs) Handles DataGrid1.PageI ndexChanged
DataGrid1.Curre ntPageIndex = e.NewPageIndex
BindData()

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

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

Similar topics

4
2803
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 sorting i.e. sort by col1 asc, then by col2 desc etc. Can anyone help ?
2
945
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 datagrid. HTML Datagrid1 TemplateColumn Table Header information Detail Information
3
3116
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 sorts twice because I inserted a messagebox in the dgMouse (MouseUp) event. Before ok is pressed, the table changes from the order it was loaded to...
0
952
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 enabled sorting.even the item command is not firing for the inner grid.I am binding the datagrid onPrerender. <ASP:DATAGRID id="MainDataGrid"...
0
1196
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 enabled sorting.even the item command is not firing for the inner grid.I am binding the datagrid onPrerender. <ASP:DATAGRID id="MainDataGrid"...
8
4140
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 repeater working, and paging/sorting works, but there is a small bug that I can't seem to figure out. If, for example, I display 5 records per page,...
5
2509
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 I cannot sort the data when I click on the column header. I have set the tablestype.allowsorting = true, but this has no effect.
8
15146
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 that seems to work for 99% of the cases where I need to disable datagrid column sorting: Private Sub datagrid_MouseDown(ByVal sender As Object,...
0
1685
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 OnEditCommand event is raised, I try to do the following: 1. Find the selected datalist item in which the nested datagrid raised the event. (by...
0
7464
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7805
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7413
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
1
5323
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4943
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3449
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3440
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1012
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
700
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.