Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HOW TO: Using sorting / paging on GridView w/o a DataSourceControl

Status
Not open for further replies.

kebele

MIS
Joined
Jul 31, 2006
Messages
107
Location
US
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">
&nbsp;<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>&nbsp;&nbsp;<br />
<br />
<strong><em>
Last
Plan / Proposal &nbsp;Purchased &nbsp;Date &nbsp; </em></strong>
<br />
<asp:DropDownList ID="drPur" runat="server" Width="96px">
</asp:DropDownList>


<asp:DropDownList ID="drPurM" runat="server" Width="96px">
</asp:DropDownList><br />
&nbsp;<br />
<strong><em>Sort Order</em></strong><br />
<asp:DropDownList
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:DropDownList>
&nbsp; &nbsp;&nbsp;
<asp:DropDownList
id="DirectionList"
Runat="server"
Font-Bold="False"
Font-Italic="False" >
<asp:ListItem Text="Ascending" />
<asp:ListItem Text="Descending" />
</asp:DropDownList>
<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>
 
Hi all,
Sorry for asking this question again.I have been working on this project for two days now but still did not figure out how i can i make it to work.my problem is i would like to use two dropdowns one for the field for gridview value to vebue to be sorted the second one is to select ascending or descendig order.I am working w/o datasource control my question is can i include this in my click event?which i am doubting if not how can i get around with this problem. I really appreciate your help and patient as i am struggling to lear asp.net


Sub gvSearch_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles gvSearch.Sorting


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top