Can not sort datagrid

G

Guest

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,
 
J

Jon

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
 
G

Guest

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 said:
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
 
J

Jon

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

Jon

Joe said:
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
 
G

Guest

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?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,968
Messages
2,570,154
Members
46,702
Latest member
LukasConde

Latest Threads

Top