![]() |
AspNet DataGrid won't fire sort routine
Hello to all,
I have an asp.net application that uses a datagrid but it won't fire the sort command even though I've set the allow sort to true. Any idea's? Thanks in advance Patrick Laferriere |
Re: AspNet DataGrid won't fire sort routine
Pat,
I believe you have to write the sort code yourself. Gary "PatLaf" <plaferriere@transitions.com> wrote in message news:0c6101c39e29$c3d32bb0$a501280a@phx.gbl... > Hello to all, > I have an asp.net application that uses a datagrid but it > won't fire the sort command even though I've set the > allow sort to true. Any idea's? > > Thanks in advance > Patrick Laferriere |
Re: AspNet DataGrid won't fire sort routine
Hi Patrick,
Gary is right that you need some code to make sorting work. Here is a sample. Add the following inside the HTML for the form. This adds a datagrid. <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server" AutoGenerateColumns="False" AllowSorting="True"> <Columns> <asp:BoundColumn DataField="au_id" SortExpression="au_id" HeaderText="au_id"></asp:BoundColumn> <asp:BoundColumn DataField="au_fname" SortExpression="au_fname" HeaderText="au_fname"></asp:BoundColumn> <asp:BoundColumn DataField="au_lname" SortExpression="au_lname" HeaderText="au_lname"></asp:BoundColumn> </Columns> </asp:DataGrid> Next, add the following to your code behind. Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then ViewState("SortOrder") = "DESC" ViewState("SortField") = "au_id" Bind() End If End Sub Private Sub Bind() Dim connectionString As String = "server='localhost'; trusted_connection=true; Database='pubs'" Dim sqlConnection As System.Data.SqlClient.SqlConnection = New System.Data.SqlClient.SqlConnection(connectionStri ng) Dim queryString As String = "SELECT au_id, au_fname, au_lname FROM Authors" Dim sqlCommand As System.Data.SqlClient.SqlCommand = New System.Data.SqlClient.SqlCommand(queryString, sqlConnection) Dim sqlAdapter As New SqlClient.SqlDataAdapter(sqlCommand) Dim ds As New Data.DataSet sqlAdapter.Fill(ds, "data") Dim dv As DataView dv = ds.Tables("data").DefaultView dv.Sort = ViewState("SortField") & " " & ViewState("SortOrder") DataGrid1.DataSource = dv DataGrid1.DataBind() sqlAdapter.Dispose() sqlCommand.Dispose() sqlConnection.Close() sqlConnection.Dispose() End Sub Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridSortCommandEvent Args) Handles DataGrid1.SortCommand If ViewState("SortField") = e.SortExpression Then If (ViewState("SortOrder") = "DESC") Then ViewState("SortOrder") = "ASC" Else ViewState("SortOrder") = "DESC" End If End If ViewState("SortField") = e.SortExpression Bind() End Sub Thank you, Mike Microsoft, ASP.NET Support Professional Microsoft highly recommends to all of our customers that they visit the http://www.microsoft.com/protect site and perform the three straightforward steps listed to improve your computer’s security. This posting is provided "AS IS", with no warranties, and confers no rights. -------------------- > From: "Gary Nelson" <gn@contanet.es> > References: <0c6101c39e29$c3d32bb0$a501280a@phx.gbl> > Subject: Re: AspNet DataGrid won't fire sort routine > Date: Wed, 29 Oct 2003 17:00:22 -0000 > Lines: 17 > X-Priority: 3 > X-MSMail-Priority: Normal > X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 > X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 > Message-ID: <essmp4jnDHA.2404@TK2MSFTNGP12.phx.gbl> > Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontro ls > NNTP-Posting-Host: 102.red-80-33-63.pooles.rima-tde.net 80.33.63.102 > Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP12.phx.gbl > Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.aspnet.webcontro ls:15715 > X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontro ls > > Pat, > > I believe you have to write the sort code yourself. > > Gary > > "PatLaf" <plaferriere@transitions.com> wrote in message > news:0c6101c39e29$c3d32bb0$a501280a@phx.gbl... > > Hello to all, > > I have an asp.net application that uses a datagrid but it > > won't fire the sort command even though I've set the > > allow sort to true. Any idea's? > > > > Thanks in advance > > Patrick Laferriere > > > |
Re: AspNet DataGrid won't fire sort routine
I have the code posted that I'm trying to use. The only
real difference that I see is that you set auto gen col's to false. Could that be a factor in why this isn't working? I have code for the grid and the wire up in the behind page. My issue is that the event never triggers. It fires a page.postback but never the code to handle the sort yet I have it there. I'm kind of confused as to why this won't work. If the page post's back why doesn't it fire the grid's sort command? Regards, Pat >-----Original Message----- >Hi Patrick, > >Gary is right that you need some code to make sorting work. Here is a >sample. > >Add the following inside the HTML for the form. This adds a datagrid. > ><asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px; POSITION: >absolute; TOP: 8px" runat="server" > AutoGenerateColumns="False" AllowSorting="True"> > <Columns> > <asp:BoundColumn DataField="au_id" SortExpression="au_id" >HeaderText="au_id"></asp:BoundColumn> > <asp:BoundColumn DataField="au_fname" SortExpression="au_fname" >HeaderText="au_fname"></asp:BoundColumn> > <asp:BoundColumn DataField="au_lname" SortExpression="au_lname" >HeaderText="au_lname"></asp:BoundColumn> > </Columns> ></asp:DataGrid> > > >Next, add the following to your code behind. > >Private Sub Page_Load(ByVal sender As System.Object, ByVal e As >System.EventArgs) Handles MyBase.Load > If Not IsPostBack Then > ViewState("SortOrder") = "DESC" > ViewState("SortField") = "au_id" > Bind() > End If >End Sub > >Private Sub Bind() > Dim connectionString As String = "server='localhost'; >trusted_connection=true; Database='pubs'" > Dim sqlConnection As System.Data.SqlClient.SqlConnection = New >System.Data.SqlClient.SqlConnection(connectionStr ing) > Dim queryString As String = "SELECT au_id, au_fname, au_lname FROM >Authors" > Dim sqlCommand As System.Data.SqlClient.SqlCommand = New >System.Data.SqlClient.SqlCommand(queryString, sqlConnection) > Dim sqlAdapter As New SqlClient.SqlDataAdapter (sqlCommand) > Dim ds As New Data.DataSet > sqlAdapter.Fill(ds, "data") > Dim dv As DataView > dv = ds.Tables("data").DefaultView > dv.Sort = ViewState("SortField") & " " & ViewState ("SortOrder") > DataGrid1.DataSource = dv > DataGrid1.DataBind() > sqlAdapter.Dispose() > sqlCommand.Dispose() > sqlConnection.Close() > sqlConnection.Dispose() >End Sub > >Private Sub DataGrid1_SortCommand(ByVal source As Object, ByVal e As >System.Web.UI.WebControls.DataGridSortCommandEven tArgs) Handles >DataGrid1.SortCommand > If ViewState("SortField") = e.SortExpression Then > If (ViewState("SortOrder") = "DESC") Then > ViewState("SortOrder") = "ASC" > Else > ViewState("SortOrder") = "DESC" > End If > End If > ViewState("SortField") = e.SortExpression > Bind() >End Sub > >Thank you, Mike >Microsoft, ASP.NET Support Professional > >Microsoft highly recommends to all of our customers that they visit the >http://www.microsoft.com/protect site and perform the three straightforward >steps listed to improve your computer's security. > >This posting is provided "AS IS", with no warranties, and confers no rights. > > >-------------------- >> From: "Gary Nelson" <gn@contanet.es> >> References: <0c6101c39e29$c3d32bb0$a501280a@phx.gbl> >> Subject: Re: AspNet DataGrid won't fire sort routine >> Date: Wed, 29 Oct 2003 17:00:22 -0000 >> Lines: 17 >> X-Priority: 3 >> X-MSMail-Priority: Normal >> X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 >> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 >> Message-ID: <essmp4jnDHA.2404@TK2MSFTNGP12.phx.gbl> >> Newsgroups: microsoft.public.dotnet.framework.aspnet.webcontro ls >> NNTP-Posting-Host: 102.red-80-33-63.pooles.rima- tde.net 80.33.63.102 >> Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl! TK2MSFTNGP12.phx.gbl >> Xref: cpmsftngxa06.phx.gbl >microsoft.public.dotnet.framework.aspnet.webcontr ols:1571 5 >> X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.webcontro ls >> >> Pat, >> >> I believe you have to write the sort code yourself. >> >> Gary >> >> "PatLaf" <plaferriere@transitions.com> wrote in message >> news:0c6101c39e29$c3d32bb0$a501280a@phx.gbl... >> > Hello to all, >> > I have an asp.net application that uses a datagrid but it >> > won't fire the sort command even though I've set the >> > allow sort to true. Any idea's? >> > >> > Thanks in advance >> > Patrick Laferriere >> >> >> > >. > |
Re: AspNet DataGrid won't fire sort routine
Your sort event handler is not wired up. Verify this in the events property
pages. It will be empty. There is a bug where it becomes unwired sometimes. -- ----------- Got TidBits? Get it here: www.networkip.net/tidbits "PatLaf" <plaferriere@transitions.com> wrote in message news:093c01c39edf$9ccafc30$a501280a@phx.gbl... > I have the code posted that I'm trying to use. The only > real difference that I see is that you set auto gen col's > to false. Could that be a factor in why this isn't > working? I have code for the grid and the wire up in the > behind page. My issue is that the event never triggers. > It fires a page.postback but never the code to handle the > sort yet I have it there. I'm kind of confused as to why > this won't work. If the page post's back why doesn't it > fire the grid's sort command? > > Regards, > Pat > >-----Original Message----- > >Hi Patrick, > > > >Gary is right that you need some code to make sorting > work. Here is a > >sample. > > > >Add the following inside the HTML for the form. This > adds a datagrid. > > > ><asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: > 8px; POSITION: > >absolute; TOP: 8px" runat="server" > > AutoGenerateColumns="False" AllowSorting="True"> > > <Columns> > > <asp:BoundColumn DataField="au_id" > SortExpression="au_id" > >HeaderText="au_id"></asp:BoundColumn> > > <asp:BoundColumn DataField="au_fname" > SortExpression="au_fname" > >HeaderText="au_fname"></asp:BoundColumn> > > <asp:BoundColumn DataField="au_lname" > SortExpression="au_lname" > >HeaderText="au_lname"></asp:BoundColumn> > > </Columns> > ></asp:DataGrid> > > > > > >Next, add the following to your code behind. > > > >Private Sub Page_Load(ByVal sender As System.Object, > ByVal e As > >System.EventArgs) Handles MyBase.Load > > If Not IsPostBack Then > > ViewState("SortOrder") = "DESC" > > ViewState("SortField") = "au_id" > > Bind() > > End If > >End Sub > > > >Private Sub Bind() > > Dim connectionString As String = "server='localhost'; > >trusted_connection=true; Database='pubs'" > > Dim sqlConnection As > System.Data.SqlClient.SqlConnection = New > >System.Data.SqlClient.SqlConnection(connectionStr ing) > > Dim queryString As String = "SELECT au_id, au_fname, > au_lname FROM > >Authors" > > Dim sqlCommand As System.Data.SqlClient.SqlCommand = > New > >System.Data.SqlClient.SqlCommand(queryString, > sqlConnection) > > Dim sqlAdapter As New SqlClient.SqlDataAdapter > (sqlCommand) > > Dim ds As New Data.DataSet > > sqlAdapter.Fill(ds, "data") > > Dim dv As DataView > > dv = ds.Tables("data").DefaultView > > dv.Sort = ViewState("SortField") & " " & ViewState > ("SortOrder") > > DataGrid1.DataSource = dv > > DataGrid1.DataBind() > > sqlAdapter.Dispose() > > sqlCommand.Dispose() > > sqlConnection.Close() > > sqlConnection.Dispose() > >End Sub > > > >Private Sub DataGrid1_SortCommand(ByVal source As > Object, ByVal e As > >System.Web.UI.WebControls.DataGridSortCommandEven tArgs) > Handles > >DataGrid1.SortCommand > > If ViewState("SortField") = e.SortExpression Then > > If (ViewState("SortOrder") = "DESC") Then > > ViewState("SortOrder") = "ASC" > > Else > > ViewState("SortOrder") = "DESC" > > End If > > End If > > ViewState("SortField") = e.SortExpression > > Bind() > >End Sub > > > >Thank you, Mike > >Microsoft, ASP.NET Support Professional > > > >Microsoft highly recommends to all of our customers > that they visit the > >http://www.microsoft.com/protect site and perform the > three straightforward > >steps listed to improve your computer's security. > > > >This posting is provided "AS IS", with no warranties, > and confers no rights. > > > > > >-------------------- > >> From: "Gary Nelson" <gn@contanet.es> > >> References: <0c6101c39e29$c3d32bb0$a501280a@phx.gbl> > >> Subject: Re: AspNet DataGrid won't fire sort routine > >> Date: Wed, 29 Oct 2003 17:00:22 -0000 > >> Lines: 17 > >> X-Priority: 3 > >> X-MSMail-Priority: Normal > >> X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 > >> X-MimeOLE: Produced By Microsoft MimeOLE > V6.00.2800.1165 > >> Message-ID: <essmp4jnDHA.2404@TK2MSFTNGP12.phx.gbl> > >> Newsgroups: > microsoft.public.dotnet.framework.aspnet.webcontro ls > >> NNTP-Posting-Host: 102.red-80-33-63.pooles.rima- > tde.net 80.33.63.102 > >> Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl! > TK2MSFTNGP12.phx.gbl > >> Xref: cpmsftngxa06.phx.gbl > >microsoft.public.dotnet.framework.aspnet.webcontr ols:1571 > 5 > >> X-Tomcat-NG: > microsoft.public.dotnet.framework.aspnet.webcontro ls > >> > >> Pat, > >> > >> I believe you have to write the sort code yourself. > >> > >> Gary > >> > >> "PatLaf" <plaferriere@transitions.com> wrote in message > >> news:0c6101c39e29$c3d32bb0$a501280a@phx.gbl... > >> > Hello to all, > >> > I have an asp.net application that uses a datagrid > but it > >> > won't fire the sort command even though I've set the > >> > allow sort to true. Any idea's? > >> > > >> > Thanks in advance > >> > Patrick Laferriere > >> > >> > >> > > > >. > > |
| All times are GMT. The time now is 05:18 PM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.