Hi all,
I am working to create paging and sorting Using sorting / paging on GridView w/o a DataSourceControl DataSource. the paging part works fine.The sorting part i have two dropdowns for the user to select the field they would like to sort and also can make a selection from the second dropdown to sort either Ascending or Descending order and this part is not working for me.Can someone give me an idea why i am not able to get it to work? below is my code.Thanks a bunch.
Protected Sub gvSearch_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gvSearch.Sorting
Dim expression As String = ""
Dim direction As SortDirection
expression = SortList1.SelectedValue
Select Case DirectionList.SelectedValue
Case "Ascending"
direction = SortDirection.Ascending
Case "Descending"
direction = SortDirection.Descending
Case Else
direction = SortDirection.Ascending
End Select
gvSearch.Sort(expression, direction)
End Sub
<html xmlns=" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<strong><em>Today's date :</em></strong>
<asp:Label ID="lblDate" runat="server" Font-Bold="True" ForeColor="#FF3366" Width="112px"></asp:Label><br />
<br />
<strong><em>
Vendor Name</em></strong><br />
<asp:TextBox ID="txtVendorName" runat="server" Width="512px"></asp:TextBox><br />
<br />
<strong><em>
State</em></strong><br />
<asp:ListBox ID="lstState" runat="server" DataTextField="astate" SelectionMode=Multiple AppendDataBoundItems=true Width="64px">
</asp:ListBox> <br />
<br />
<strong><em>
Last
Plan / Proposal Purchased Date </em></strong>
<br />
<asp
ropDownList ID="drPur" runat="server" Width="96px">
</asp
ropDownList>
<asp
ropDownList ID="drPurM" runat="server" Width="96px">
</asp
ropDownList><br />
<br />
<strong><em>Sort Order</em></strong><br />
<asp
ropDownList
id="SortList1"
Runat="server"
Font-Bold="False"
Font-Italic="False" Width="96px" >
<asp:ListItem Text="Vendor Id" />
<asp:ListItem Text="Vendor Name" />
<asp:ListItem Text="Plan Purchase Date" />
</asp
ropDownList>
<asp
ropDownList
id="DirectionList"
Runat="server"
Font-Bold="False"
Font-Italic="False" >
<asp:ListItem Text="Ascending" />
<asp:ListItem Text="Descending" />
</asp
ropDownList>
<asp:Button ID="Button1" runat="server" Text="Vendor Search" />
<asp:Button
ID="btnReset" runat="server" Text="Reset" Width="136px" /><br />
<br />
<asp:GridView ID="gvSearch" runat="server"
CellPadding="4" ForeColor="#333333" Font-Size="Smaller"
HorizontalAlign="Left" Width="100%"
AutoGenerateColumns="False" AllowPaging=true AllowSorting=true
OnPageIndexChanging="gvSearch_PageIndexChanging"
onSorting="gvSearch_Sorting">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Font-Size="Small" HorizontalAlign="Left" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="vendor"
HeaderText="Vendor Id"
SortExpression="vendor">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="addrnum" HeaderText="Sq" />
<asp:BoundField DataField="vnamel"
HeaderText="Vendor Name"
SortExpression="vnamel" />
<asp:BoundField DataField="aaddr1" HeaderText="Address" />
<asp:BoundField DataField="acity" HeaderText="City" >
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="astate" HeaderText="State" />
<asp:BoundField DataField="azipcode" HeaderText="Zip Code">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="aphone" HeaderText="Phone Number">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="vasst1" HeaderText="Fax Number" >
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Last_plan_purchased_date" HeaderText="Last Plan / Proposal Purchased Date" SortExpression="Last_plan_purchased_date" />
</Columns>
</asp:GridView>
<br />
</form>
</body>
</html>
I am working to create paging and sorting Using sorting / paging on GridView w/o a DataSourceControl DataSource. the paging part works fine.The sorting part i have two dropdowns for the user to select the field they would like to sort and also can make a selection from the second dropdown to sort either Ascending or Descending order and this part is not working for me.Can someone give me an idea why i am not able to get it to work? below is my code.Thanks a bunch.
Protected Sub gvSearch_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gvSearch.Sorting
Dim expression As String = ""
Dim direction As SortDirection
expression = SortList1.SelectedValue
Select Case DirectionList.SelectedValue
Case "Ascending"
direction = SortDirection.Ascending
Case "Descending"
direction = SortDirection.Descending
Case Else
direction = SortDirection.Ascending
End Select
gvSearch.Sort(expression, direction)
End Sub
<html xmlns=" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<strong><em>Today's date :</em></strong>
<asp:Label ID="lblDate" runat="server" Font-Bold="True" ForeColor="#FF3366" Width="112px"></asp:Label><br />
<br />
<strong><em>
Vendor Name</em></strong><br />
<asp:TextBox ID="txtVendorName" runat="server" Width="512px"></asp:TextBox><br />
<br />
<strong><em>
State</em></strong><br />
<asp:ListBox ID="lstState" runat="server" DataTextField="astate" SelectionMode=Multiple AppendDataBoundItems=true Width="64px">
</asp:ListBox> <br />
<br />
<strong><em>
Last
Plan / Proposal Purchased Date </em></strong>
<br />
<asp

</asp

<asp

</asp

<br />
<strong><em>Sort Order</em></strong><br />
<asp

id="SortList1"
Runat="server"
Font-Bold="False"
Font-Italic="False" Width="96px" >
<asp:ListItem Text="Vendor Id" />
<asp:ListItem Text="Vendor Name" />
<asp:ListItem Text="Plan Purchase Date" />
</asp

<asp

id="DirectionList"
Runat="server"
Font-Bold="False"
Font-Italic="False" >
<asp:ListItem Text="Ascending" />
<asp:ListItem Text="Descending" />
</asp

<asp:Button ID="Button1" runat="server" Text="Vendor Search" />
<asp:Button
ID="btnReset" runat="server" Text="Reset" Width="136px" /><br />
<br />
<asp:GridView ID="gvSearch" runat="server"
CellPadding="4" ForeColor="#333333" Font-Size="Smaller"
HorizontalAlign="Left" Width="100%"
AutoGenerateColumns="False" AllowPaging=true AllowSorting=true
OnPageIndexChanging="gvSearch_PageIndexChanging"
onSorting="gvSearch_Sorting">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Font-Size="Small" HorizontalAlign="Left" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:BoundField DataField="vendor"
HeaderText="Vendor Id"
SortExpression="vendor">
<ItemStyle Wrap="False" />
<HeaderStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="addrnum" HeaderText="Sq" />
<asp:BoundField DataField="vnamel"
HeaderText="Vendor Name"
SortExpression="vnamel" />
<asp:BoundField DataField="aaddr1" HeaderText="Address" />
<asp:BoundField DataField="acity" HeaderText="City" >
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="astate" HeaderText="State" />
<asp:BoundField DataField="azipcode" HeaderText="Zip Code">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="aphone" HeaderText="Phone Number">
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="vasst1" HeaderText="Fax Number" >
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="Last_plan_purchased_date" HeaderText="Last Plan / Proposal Purchased Date" SortExpression="Last_plan_purchased_date" />
</Columns>
</asp:GridView>
<br />
</form>
</body>
</html>