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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

GridView Sorting issues...

Status
Not open for further replies.

VisualGuy

Programmer
May 27, 2003
162
US
I think my problem is that I'm just not understanding what is happening on my page...

I have a textbox and a button that takes the value of the textbox and performs a SQL Search against a viewgrid...



<asp:GridView ID="GridView2" runat="server" AllowSorting="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px"
CellPadding="3" CellSpacing="2" AlternatingRowStyle-BackColor="#CCFFFF" >
<FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" />
<RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" />
<Columns>
<asp:HyperLinkField DataTextField="Account_Number" HeaderText="AccountNumber"
NavigateUrl="[0]&amp;country=[1]" SortExpression="Account_Number" />
<asp:BoundField DataField="Full_Name" HeaderText="Full_Name"
SortExpression="Full_Name" />
<asp:BoundField DataField="Last_Name" HeaderText="Last_Name"
SortExpression="Last_Name" />
<asp:BoundField DataField="Social_Number" HeaderText="Social_Number"
SortExpression="Social_Number" />
</Columns>
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" />

<AlternatingRowStyle BackColor="#CCFFFF"></AlternatingRowStyle>
</asp:GridView>

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:purgedAccountsConnectionString %>" >
</asp:SqlDataSource>

______________

When I click the button, I perform the search and fill the grid as such...

Sub RunQuery()

SqlDataSource1.SelectCommand = "Select * FROM ALPAccounts WHERE Last_Name LIKE '" & TextBox1.Text & "' ORDER BY Full_Name"

End Sub

___________

I've tried using the GridView2_Sorting sub, but that didn't get me anywhere. Why is this so difficult. What should I be doing?
 
a couple issues.

1st. don't use datasource controls. you cannot debug/test them and your presentation code shouldn't know about databases.

2nd. don't use injected sql. use parameterized queries. there are a number of benefits to this. google for more details.

3rd. have you defined your sort implementation, or are you letting the grid/datasource do this automagically? if the latter it's just another reason not use datasource controls.

instead fetch your data without any sorting. then sort the results client side. since your paging from the client (code, not db) sorting on the client (code) isn't an issue.

once common problem most webform developers encounter is they put all there code into the markup and codebehind. therefore you have a handful of objects doing all the work. this is perpetuated by MS help/examples.

all the webform/code behind should do is put values into html and get values out of html. the rest of the work (logic, data access, security, logging, etc) should be done outside of any references to System.Web.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top