GridView.Sort problem

  • Thread starter Thread starter bfwd
  • Start date Start date
B

bfwd

I have the following in VS 2008. I get a stack overflow condition
raised when it tries to execute the
"GridView1.Sort(expression, direction)" statement in the
GridView1_Sorting event handler. Is there recursion going on here that
I do not see?
-------------------------------------------------------------------------------------------------------------------------------------------------
<asp:GridView ID="GridView1" runat="server" AllowSorting="True"
AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True"
AutoGenerateSelectButton="True" BackColor="White"
BorderColor="#999999"
BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical"
onsorting="Gridview1_Sorting"
OnSorted="Gridview1_sorted"
onselectedindexchanged="GridView1_SelectedIndexChanged"
onrowediting="GridView1_RowEditing" >
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True"
ForeColor="White" />
<HeaderStyle BackColor="#000084" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="Gainsboro" />
</asp:GridView>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
If Not IsPostBack Then
sqlcmd = New SqlCommand("select * from
dbo.semestertable", myDB)
myDB.Open()
reader = sqlcmd.ExecuteReader
GridView1.DataSource = reader
GridView1.DataBind()
myDB.Close()
End If
End Sub

Sub GridView1_Sorting(ByVal sender As Object, ByVal e As
GridViewSortEventArgs)
Dim expression As String
Dim direction As SortDirection
expression = e.SortExpression
If e.SortDirection = SortDirection.Ascending Then
direction = SortDirection.Descending
Else
direction = SortDirection.Ascending
End If
GridView1.Sort(expression, direction)
End Sub

Sub GridView1_Sorted(ByVal sender As Object, ByVal e As
EventArgs)
message.text = "you sorted on column: " &
GridView1.SortExpression & _
" in " & GridView1.SortDirection & " order"
message.visible = True
End Sub

--------------------------------------------------------------------------------------------------------------------------------
 
I have the following in VS 2008. I get a stack overflow condition
raised when it tries to execute the
"GridView1.Sort(expression, direction)" statement in the
GridView1_Sorting event handler. Is there recursion going on here that
I do not see?
---------------------------------------------------------------------------­----------------------------------------------------------------------
 <asp:GridView ID="GridView1" runat="server" AllowSorting="True"
              AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True"
              AutoGenerateSelectButton="True" BackColor="White"
BorderColor="#999999"
              BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical"
              onsorting="Gridview1_Sorting"
OnSorted="Gridview1_sorted"
              onselectedindexchanged="GridView1_SelectedIndexChanged"
              onrowediting="GridView1_RowEditing" >
              <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
              <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
              <PagerStyle BackColor="#999999" ForeColor="Black"
HorizontalAlign="Center" />
              <SelectedRowStyle BackColor="#008A8C" Font-Bold="True"
ForeColor="White" />
              <HeaderStyle BackColor="#000084" Font-Bold="True"
ForeColor="White" />
              <AlternatingRowStyle BackColor="Gainsboro" />
         </asp:GridView>

     Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load
          If Not IsPostBack Then
               sqlcmd = New SqlCommand("select * from
dbo.semestertable", myDB)
               myDB.Open()
               reader = sqlcmd.ExecuteReader
               GridView1.DataSource = reader
               GridView1.DataBind()
               myDB.Close()
          End If
     End Sub

     Sub GridView1_Sorting(ByVal sender As Object, ByVal e As
GridViewSortEventArgs)
          Dim expression As String
          Dim direction As SortDirection
          expression = e.SortExpression
          If e.SortDirection = SortDirection.Ascending Then
               direction = SortDirection.Descending
          Else
               direction = SortDirection.Ascending
          End If
          GridView1.Sort(expression, direction)
     End Sub

     Sub GridView1_Sorted(ByVal sender As Object, ByVal e As
EventArgs)
          message.text = "you sorted on column: " &
GridView1.SortExpression & _
               " in " & GridView1.SortDirection & " order"
          message.visible = True
     End Sub

---------------------------------------------------------------------------­-----------------------------------------------------

hi
you are not binding your gridview in sort event if i am not wrong..and
one more thing if you are binding your gridview with sqldatareader
then it doesn't support sorting..either you have to convert
sqldatareader to dataset or bind gridview with dataset..

That's it...

Regards,
Nil
"Never Expect..Never Regret"
 
hi
you are not binding your gridview in sort event if i am not wrong..and
one more thing if you are binding your gridview with sqldatareader
then it doesn't support sorting..either you have to convert
sqldatareader to dataset or bind gridview with dataset..

That's it...

Regards,
Nil
"Never Expect..Never Regret"- Hide quoted text -

- Show quoted text -

Right. I used a DataTable and that worked OK.
Thanks for pointing me in the right direction.
 
Back
Top