Can not sort datagrid

Discussion in 'ASP .Net' started by =?Utf-8?B?Sm9l?=, Oct 7, 2005.

  1. Hello,

    I have a datagrid in an nested html table (one table inside of another
    table) and have set the allowsSorting property to true. I've created in the
    code-behind a method (Sub - I'm using VB.NET) that handles the SortCommand
    event of the data grid. I've included the declaration of the Sub below.
    EnableViewState is set to false; we reload the DataSource each time the page
    posts.

    Would anyone know why this DataGrid doesn't sort? The web server isn't
    executing the SortCommand event handler.

    If tehre is any other information that I can offer, please elt me know.
    This really has me stumped.

    Sub Declaration:*********************************
    Private Sub SortDataGridColumns(ByVal sender As System.Object, ByVal e As
    System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
    dgForms.SortCommand

    PopulateClaimFormsDataGrid(e.SortExpression,
    SwapSortDirection(e.SortExpression))
    End Sub
    *********************************************

    Data Grid HTML**********************************
    <asp:datagrid id="dgForms" runat="server" CssClass="Interior"
    AllowSorting="True" AutoGenerateColumns="False">
    <AlternatingItemStyle
    BackColor="GhostWhite"></AlternatingItemStyle> <ItemStyle
    BackColor="Gainsboro"></ItemStyle>
    <Columns>
    <asp:HyperLinkColumn Target="_self"
    DataNavigateUrlField="Form_Path_File_NM" DataTextField="Form_Number"
    SortExpression="Form_Number" HeaderText="NUMBER">
    <HeaderStyle Width="10%" CssClass="TableHeader"></HeaderStyle>
    <ItemStyle CssClass="TableData"></ItemStyle>
    </asp:HyperLinkColumn>
    <asp:BoundColumn DataField="Form_Name" SortExpression="Form_Name"
    HeaderText="NAME">
    <HeaderStyle Width="50%" CssClass="TableHeader"></HeaderStyle>
    <ItemStyle CssClass="TableData"></ItemStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="Description"
    SortExpression="Description" HeaderText="CATEGORY">
    <HeaderStyle Width="25%" CssClass="TableHeader"></HeaderStyle>
    <ItemStyle CssClass="TableData"></ItemStyle>
    </asp:BoundColumn>
    <asp:BoundColumn DataField="Form_State_CD"
    SortExpression="Form_State_CD" HeaderText="STATE">
    <HeaderStyle Width="15%" CssClass="TableHeader"></HeaderStyle>
    <ItemStyle CssClass="TableData"></ItemStyle>
    </asp:BoundColumn>
    </Columns>
    </asp:datagrid>
    *********************************************

    TIA,

    --
    Joe

    VBA Automation/VB 6/C++/C#/ VB.NET/Web and DB development
     
    =?Utf-8?B?Sm9l?=, Oct 7, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?Sm9l?=

    Jon Guest

    We need to see what you do in PopulateClaimFormsDataGrid

    You would need to create a DataView and set it Sort property to the
    e.SortExpression param you pass then bind the DataGrid to the DataView


    "Joe" <> wrote in message
    news:...
    > Hello,
    >
    > I have a datagrid in an nested html table (one table inside of another
    > table) and have set the allowsSorting property to true. I've created in
    > the
    > code-behind a method (Sub - I'm using VB.NET) that handles the SortCommand
    > event of the data grid. I've included the declaration of the Sub below.
    > EnableViewState is set to false; we reload the DataSource each time the
    > page
    > posts.
    >
    > Would anyone know why this DataGrid doesn't sort? The web server isn't
    > executing the SortCommand event handler.
    >
    > If tehre is any other information that I can offer, please elt me know.
    > This really has me stumped.
    >
    > Sub Declaration:*********************************
    > Private Sub SortDataGridColumns(ByVal sender As System.Object, ByVal e As
    > System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
    > dgForms.SortCommand
    >
    > PopulateClaimFormsDataGrid(e.SortExpression,
    > SwapSortDirection(e.SortExpression))
    > End Sub
    > *********************************************
    >
    > Data Grid HTML**********************************
    > <asp:datagrid id="dgForms" runat="server" CssClass="Interior"
    > AllowSorting="True" AutoGenerateColumns="False">
    > <AlternatingItemStyle
    > BackColor="GhostWhite"></AlternatingItemStyle> <ItemStyle
    > BackColor="Gainsboro"></ItemStyle>
    > <Columns>
    > <asp:HyperLinkColumn Target="_self"
    > DataNavigateUrlField="Form_Path_File_NM" DataTextField="Form_Number"
    > SortExpression="Form_Number" HeaderText="NUMBER">
    > <HeaderStyle Width="10%" CssClass="TableHeader"></HeaderStyle>
    > <ItemStyle CssClass="TableData"></ItemStyle>
    > </asp:HyperLinkColumn>
    > <asp:BoundColumn DataField="Form_Name" SortExpression="Form_Name"
    > HeaderText="NAME">
    > <HeaderStyle Width="50%" CssClass="TableHeader"></HeaderStyle>
    > <ItemStyle CssClass="TableData"></ItemStyle>
    > </asp:BoundColumn>
    > <asp:BoundColumn DataField="Description"
    > SortExpression="Description" HeaderText="CATEGORY">
    > <HeaderStyle Width="25%" CssClass="TableHeader"></HeaderStyle>
    > <ItemStyle CssClass="TableData"></ItemStyle>
    > </asp:BoundColumn>
    > <asp:BoundColumn DataField="Form_State_CD"
    > SortExpression="Form_State_CD" HeaderText="STATE">
    > <HeaderStyle Width="15%" CssClass="TableHeader"></HeaderStyle>
    > <ItemStyle CssClass="TableData"></ItemStyle>
    > </asp:BoundColumn>
    > </Columns>
    > </asp:datagrid>
    > *********************************************
    >
    > TIA,
    >
    > --
    > Joe
    >
    > VBA Automation/VB 6/C++/C#/ VB.NET/Web and DB development
     
    Jon, Oct 8, 2005
    #2
    1. Advertising

  3. Jon,

    Sorry for the delay. I do create a dataview. Here's the code:

    Private Sub PopulateClaimFormsDataGrid(ByVal OrderBy As String, ByVal
    SortDirection As String)

    'Retrieve Claim Froms data from database
    Dim cForm As New ClaimForm
    dtClaimForms = cForm.LoadClaimForms(hdnLineOfBusniessID.Value,
    hdnSearchText.Value, hdnSelectedCategory.Value, OrderBy, SortDirection)

    'If Claim Forms are found, display sorted data
    If dtClaimForms.Rows.Count > 0 Then
    Dim dvForms As New DataView
    dvForms = dtClaimForms.DefaultView

    lblFormMsg.Text = String.Empty
    dgForms.DataSource = dvForms
    dgForms.DataBind()
    Else
    lblFormMsg.Text = "Can't locate any forms for the provided data."
    ClearClaimsFormsDataGrid()
    End If

    cForm = Nothing
    End Sub


    This is not the problem. The SortCommand event is never called. So, this
    function doesn't matter. The question is, why is the web server not firing
    the SortCommand event for the datagrid....

    Thanks,

    Joe
    --
    Joe

    VBA Automation/VB/C++/Web and DB development


    "Jon" wrote:

    > We need to see what you do in PopulateClaimFormsDataGrid
    >
    > You would need to create a DataView and set it Sort property to the
    > e.SortExpression param you pass then bind the DataGrid to the DataView
    >
    >
    > "Joe" <> wrote in message
    > news:...
    > > Hello,
    > >
    > > I have a datagrid in an nested html table (one table inside of another
    > > table) and have set the allowsSorting property to true. I've created in
    > > the
    > > code-behind a method (Sub - I'm using VB.NET) that handles the SortCommand
    > > event of the data grid. I've included the declaration of the Sub below.
    > > EnableViewState is set to false; we reload the DataSource each time the
    > > page
    > > posts.
    > >
    > > Would anyone know why this DataGrid doesn't sort? The web server isn't
    > > executing the SortCommand event handler.
    > >
    > > If tehre is any other information that I can offer, please elt me know.
    > > This really has me stumped.
    > >
    > > Sub Declaration:*********************************
    > > Private Sub SortDataGridColumns(ByVal sender As System.Object, ByVal e As
    > > System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
    > > dgForms.SortCommand
    > >
    > > PopulateClaimFormsDataGrid(e.SortExpression,
    > > SwapSortDirection(e.SortExpression))
    > > End Sub
    > > *********************************************
    > >
    > > Data Grid HTML**********************************
    > > <asp:datagrid id="dgForms" runat="server" CssClass="Interior"
    > > AllowSorting="True" AutoGenerateColumns="False">
    > > <AlternatingItemStyle
    > > BackColor="GhostWhite"></AlternatingItemStyle> <ItemStyle
    > > BackColor="Gainsboro"></ItemStyle>
    > > <Columns>
    > > <asp:HyperLinkColumn Target="_self"
    > > DataNavigateUrlField="Form_Path_File_NM" DataTextField="Form_Number"
    > > SortExpression="Form_Number" HeaderText="NUMBER">
    > > <HeaderStyle Width="10%" CssClass="TableHeader"></HeaderStyle>
    > > <ItemStyle CssClass="TableData"></ItemStyle>
    > > </asp:HyperLinkColumn>
    > > <asp:BoundColumn DataField="Form_Name" SortExpression="Form_Name"
    > > HeaderText="NAME">
    > > <HeaderStyle Width="50%" CssClass="TableHeader"></HeaderStyle>
    > > <ItemStyle CssClass="TableData"></ItemStyle>
    > > </asp:BoundColumn>
    > > <asp:BoundColumn DataField="Description"
    > > SortExpression="Description" HeaderText="CATEGORY">
    > > <HeaderStyle Width="25%" CssClass="TableHeader"></HeaderStyle>
    > > <ItemStyle CssClass="TableData"></ItemStyle>
    > > </asp:BoundColumn>
    > > <asp:BoundColumn DataField="Form_State_CD"
    > > SortExpression="Form_State_CD" HeaderText="STATE">
    > > <HeaderStyle Width="15%" CssClass="TableHeader"></HeaderStyle>
    > > <ItemStyle CssClass="TableData"></ItemStyle>
    > > </asp:BoundColumn>
    > > </Columns>
    > > </asp:datagrid>
    > > *********************************************
    > >
    > > TIA,
    > >
    > > --
    > > Joe
    > >
    > > VBA Automation/VB 6/C++/C#/ VB.NET/Web and DB development

    >
    >
    >
     
    =?Utf-8?B?Sm9l?=, Oct 10, 2005
    #3
  4. =?Utf-8?B?Sm9l?=

    Jon Guest

    Before the line
    dgForms.DataSource = dvForms
    add
    dvForms.Sort(OrderBy)

    Jon

    "Joe" <> wrote in message
    news:...
    > Jon,
    >
    > Sorry for the delay. I do create a dataview. Here's the code:
    >
    > Private Sub PopulateClaimFormsDataGrid(ByVal OrderBy As String, ByVal
    > SortDirection As String)
    >
    > 'Retrieve Claim Froms data from database
    > Dim cForm As New ClaimForm
    > dtClaimForms = cForm.LoadClaimForms(hdnLineOfBusniessID.Value,
    > hdnSearchText.Value, hdnSelectedCategory.Value, OrderBy, SortDirection)
    >
    > 'If Claim Forms are found, display sorted data
    > If dtClaimForms.Rows.Count > 0 Then
    > Dim dvForms As New DataView
    > dvForms = dtClaimForms.DefaultView
    >
    > lblFormMsg.Text = String.Empty
    > dgForms.DataSource = dvForms
    > dgForms.DataBind()
    > Else
    > lblFormMsg.Text = "Can't locate any forms for the provided
    > data."
    > ClearClaimsFormsDataGrid()
    > End If
    >
    > cForm = Nothing
    > End Sub
    >
    >
    > This is not the problem. The SortCommand event is never called. So, this
    > function doesn't matter. The question is, why is the web server not
    > firing
    > the SortCommand event for the datagrid....
    >
    > Thanks,
    >
    > Joe
    > --
    > Joe
    >
    > VBA Automation/VB/C++/Web and DB development
    >
    >
    > "Jon" wrote:
    >
    >> We need to see what you do in PopulateClaimFormsDataGrid
    >>
    >> You would need to create a DataView and set it Sort property to the
    >> e.SortExpression param you pass then bind the DataGrid to the DataView
    >>
    >>
    >> "Joe" <> wrote in message
    >> news:...
    >> > Hello,
    >> >
    >> > I have a datagrid in an nested html table (one table inside of another
    >> > table) and have set the allowsSorting property to true. I've created
    >> > in
    >> > the
    >> > code-behind a method (Sub - I'm using VB.NET) that handles the
    >> > SortCommand
    >> > event of the data grid. I've included the declaration of the Sub
    >> > below.
    >> > EnableViewState is set to false; we reload the DataSource each time the
    >> > page
    >> > posts.
    >> >
    >> > Would anyone know why this DataGrid doesn't sort? The web server isn't
    >> > executing the SortCommand event handler.
    >> >
    >> > If tehre is any other information that I can offer, please elt me know.
    >> > This really has me stumped.
    >> >
    >> > Sub Declaration:*********************************
    >> > Private Sub SortDataGridColumns(ByVal sender As System.Object, ByVal e
    >> > As
    >> > System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
    >> > dgForms.SortCommand
    >> >
    >> > PopulateClaimFormsDataGrid(e.SortExpression,
    >> > SwapSortDirection(e.SortExpression))
    >> > End Sub
    >> > *********************************************
    >> >
    >> > Data Grid HTML**********************************
    >> > <asp:datagrid id="dgForms" runat="server" CssClass="Interior"
    >> > AllowSorting="True" AutoGenerateColumns="False">
    >> > <AlternatingItemStyle
    >> > BackColor="GhostWhite"></AlternatingItemStyle> <ItemStyle
    >> > BackColor="Gainsboro"></ItemStyle>
    >> > <Columns>
    >> > <asp:HyperLinkColumn Target="_self"
    >> > DataNavigateUrlField="Form_Path_File_NM" DataTextField="Form_Number"
    >> > SortExpression="Form_Number" HeaderText="NUMBER">
    >> > <HeaderStyle Width="10%" CssClass="TableHeader"></HeaderStyle>
    >> > <ItemStyle CssClass="TableData"></ItemStyle>
    >> > </asp:HyperLinkColumn>
    >> > <asp:BoundColumn DataField="Form_Name" SortExpression="Form_Name"
    >> > HeaderText="NAME">
    >> > <HeaderStyle Width="50%" CssClass="TableHeader"></HeaderStyle>
    >> > <ItemStyle CssClass="TableData"></ItemStyle>
    >> > </asp:BoundColumn>
    >> > <asp:BoundColumn DataField="Description"
    >> > SortExpression="Description" HeaderText="CATEGORY">
    >> > <HeaderStyle Width="25%" CssClass="TableHeader"></HeaderStyle>
    >> > <ItemStyle CssClass="TableData"></ItemStyle>
    >> > </asp:BoundColumn>
    >> > <asp:BoundColumn DataField="Form_State_CD"
    >> > SortExpression="Form_State_CD" HeaderText="STATE">
    >> > <HeaderStyle Width="15%" CssClass="TableHeader"></HeaderStyle>
    >> > <ItemStyle CssClass="TableData"></ItemStyle>
    >> > </asp:BoundColumn>
    >> > </Columns>
    >> > </asp:datagrid>
    >> > *********************************************
    >> >
    >> > TIA,
    >> >
    >> > --
    >> > Joe
    >> >
    >> > VBA Automation/VB 6/C++/C#/ VB.NET/Web and DB development

    >>
    >>
    >>
     
    Jon, Oct 11, 2005
    #4
  5. Jon,

    Thanks for your suggestion. This however doesn't solve the problem.

    The issue is that the SortCommand Event handler isn't firing. The code
    works. The initial sort if handled in the SQL built in another class. The
    event handler isn't firing. Do you have any idea why?
    --
    Joe

    VBA Automation/VB/C++/Web and DB development


    "Jon" wrote:

    > Before the line
    > dgForms.DataSource = dvForms
    > add
    > dvForms.Sort(OrderBy)
    >
    > Jon
    >
    > "Joe" <> wrote in message
    > news:...
    > > Jon,
    > >
    > > Sorry for the delay. I do create a dataview. Here's the code:
    > >
    > > Private Sub PopulateClaimFormsDataGrid(ByVal OrderBy As String, ByVal
    > > SortDirection As String)
    > >
    > > 'Retrieve Claim Froms data from database
    > > Dim cForm As New ClaimForm
    > > dtClaimForms = cForm.LoadClaimForms(hdnLineOfBusniessID.Value,
    > > hdnSearchText.Value, hdnSelectedCategory.Value, OrderBy, SortDirection)
    > >
    > > 'If Claim Forms are found, display sorted data
    > > If dtClaimForms.Rows.Count > 0 Then
    > > Dim dvForms As New DataView
    > > dvForms = dtClaimForms.DefaultView
    > >
    > > lblFormMsg.Text = String.Empty
    > > dgForms.DataSource = dvForms
    > > dgForms.DataBind()
    > > Else
    > > lblFormMsg.Text = "Can't locate any forms for the provided
    > > data."
    > > ClearClaimsFormsDataGrid()
    > > End If
    > >
    > > cForm = Nothing
    > > End Sub
    > >
    > >
    > > This is not the problem. The SortCommand event is never called. So, this
    > > function doesn't matter. The question is, why is the web server not
    > > firing
    > > the SortCommand event for the datagrid....
    > >
    > > Thanks,
    > >
    > > Joe
    > > --
    > > Joe
    > >
    > > VBA Automation/VB/C++/Web and DB development
    > >
    > >
    > > "Jon" wrote:
    > >
    > >> We need to see what you do in PopulateClaimFormsDataGrid
    > >>
    > >> You would need to create a DataView and set it Sort property to the
    > >> e.SortExpression param you pass then bind the DataGrid to the DataView
    > >>
    > >>
    > >> "Joe" <> wrote in message
    > >> news:...
    > >> > Hello,
    > >> >
    > >> > I have a datagrid in an nested html table (one table inside of another
    > >> > table) and have set the allowsSorting property to true. I've created
    > >> > in
    > >> > the
    > >> > code-behind a method (Sub - I'm using VB.NET) that handles the
    > >> > SortCommand
    > >> > event of the data grid. I've included the declaration of the Sub
    > >> > below.
    > >> > EnableViewState is set to false; we reload the DataSource each time the
    > >> > page
    > >> > posts.
    > >> >
    > >> > Would anyone know why this DataGrid doesn't sort? The web server isn't
    > >> > executing the SortCommand event handler.
    > >> >
    > >> > If tehre is any other information that I can offer, please elt me know.
    > >> > This really has me stumped.
    > >> >
    > >> > Sub Declaration:*********************************
    > >> > Private Sub SortDataGridColumns(ByVal sender As System.Object, ByVal e
    > >> > As
    > >> > System.Web.UI.WebControls.DataGridSortCommandEventArgs) Handles
    > >> > dgForms.SortCommand
    > >> >
    > >> > PopulateClaimFormsDataGrid(e.SortExpression,
    > >> > SwapSortDirection(e.SortExpression))
    > >> > End Sub
    > >> > *********************************************
    > >> >
    > >> > Data Grid HTML**********************************
    > >> > <asp:datagrid id="dgForms" runat="server" CssClass="Interior"
    > >> > AllowSorting="True" AutoGenerateColumns="False">
    > >> > <AlternatingItemStyle
    > >> > BackColor="GhostWhite"></AlternatingItemStyle> <ItemStyle
    > >> > BackColor="Gainsboro"></ItemStyle>
    > >> > <Columns>
    > >> > <asp:HyperLinkColumn Target="_self"
    > >> > DataNavigateUrlField="Form_Path_File_NM" DataTextField="Form_Number"
    > >> > SortExpression="Form_Number" HeaderText="NUMBER">
    > >> > <HeaderStyle Width="10%" CssClass="TableHeader"></HeaderStyle>
    > >> > <ItemStyle CssClass="TableData"></ItemStyle>
    > >> > </asp:HyperLinkColumn>
    > >> > <asp:BoundColumn DataField="Form_Name" SortExpression="Form_Name"
    > >> > HeaderText="NAME">
    > >> > <HeaderStyle Width="50%" CssClass="TableHeader"></HeaderStyle>
    > >> > <ItemStyle CssClass="TableData"></ItemStyle>
    > >> > </asp:BoundColumn>
    > >> > <asp:BoundColumn DataField="Description"
    > >> > SortExpression="Description" HeaderText="CATEGORY">
    > >> > <HeaderStyle Width="25%" CssClass="TableHeader"></HeaderStyle>
    > >> > <ItemStyle CssClass="TableData"></ItemStyle>
    > >> > </asp:BoundColumn>
    > >> > <asp:BoundColumn DataField="Form_State_CD"
    > >> > SortExpression="Form_State_CD" HeaderText="STATE">
    > >> > <HeaderStyle Width="15%" CssClass="TableHeader"></HeaderStyle>
    > >> > <ItemStyle CssClass="TableData"></ItemStyle>
    > >> > </asp:BoundColumn>
    > >> > </Columns>
    > >> > </asp:datagrid>
    > >> > *********************************************
    > >> >
    > >> > TIA,
    > >> >
    > >> > --
    > >> > Joe
    > >> >
    > >> > VBA Automation/VB 6/C++/C#/ VB.NET/Web and DB development
    > >>
    > >>
    > >>

    >
    >
    >
     
    =?Utf-8?B?Sm9l?=, Oct 11, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Eugene
    Replies:
    0
    Views:
    499
    Eugene
    Sep 28, 2004
  2. pietaster

    ItemCommand not working when datagrid can page and sort

    pietaster, Apr 7, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    13
    Views:
    305
    pietaster
    Apr 15, 2004
  3. Navin
    Replies:
    1
    Views:
    762
    Ken Schaefer
    Sep 9, 2003
  4. GIMME
    Replies:
    5
    Views:
    200
    Thomas 'PointedEars' Lahn
    Jul 26, 2004
  5. colin_lyse
    Replies:
    1
    Views:
    165
    Tore Aursand
    Feb 3, 2005
Loading...

Share This Page