I'm completely confused...
I'm binding a RS to a Gridview in ASP.NET 3.5 via VB.NET 2008.
ReturnUserid = "SELECT X , Y, Z, FROM XYZ_TABLE WHERE X = '" & Trim(TextBox1.Text) & "' ORDER BY X"
Dim DSReturnUserid As New Data.DataSet
Dim adaptorReturnUserid As SqlDataAdapter = New SqlDataAdapter(ReturnUserid, StrCon)
Dim cmdBuilderReturnUserid As SqlCommandBuilder = _
New SqlCommandBuilder(adaptorReturnUserid)
adaptorReturnUserid.Fill(DSReturnUserid)
If DSReturnUserid.Tables(0).Rows.Count > 0 Then
'TextBox1.Text = DSReturnUserid.Tables(0).Rows(0).Item(0)
GridView1.DataSource = DSReturnUserid
GridView1.DataBind()
PleaseWait.Value = ""
Else
PleaseWait.Value = "No match found. Please try again."
End If
_________________________________________
This seems to work fine, except for the fact that I cannot perform a sort. My gridview allows for sorting...
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"
AllowSorting="True" >
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<RowStyle BackColor="White" ForeColor="#330099" />
<Columns>
<asp:ButtonField ButtonType="Button" Text="Expand Details" />
</Columns>
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<AlternatingRowStyle BackColor="#99CCFF" />
</asp:GridView>
...and I'm handling the sorting in the code behind...
Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
Dim oldExpression As String = GridView1.SortExpression
Dim newExpression As String = e.SortExpression
If (oldexpression.IndexOf(newExpression) < 0) Then
If (oldexpression.Length > 0) Then
e.SortExpression = newExpression & "," & oldexpression
Else
e.SortExpression = newExpression
End If
Else
e.SortExpression = oldExpression
End If
End Sub
...Why is this not working?
I'm binding a RS to a Gridview in ASP.NET 3.5 via VB.NET 2008.
ReturnUserid = "SELECT X , Y, Z, FROM XYZ_TABLE WHERE X = '" & Trim(TextBox1.Text) & "' ORDER BY X"
Dim DSReturnUserid As New Data.DataSet
Dim adaptorReturnUserid As SqlDataAdapter = New SqlDataAdapter(ReturnUserid, StrCon)
Dim cmdBuilderReturnUserid As SqlCommandBuilder = _
New SqlCommandBuilder(adaptorReturnUserid)
adaptorReturnUserid.Fill(DSReturnUserid)
If DSReturnUserid.Tables(0).Rows.Count > 0 Then
'TextBox1.Text = DSReturnUserid.Tables(0).Rows(0).Item(0)
GridView1.DataSource = DSReturnUserid
GridView1.DataBind()
PleaseWait.Value = ""
Else
PleaseWait.Value = "No match found. Please try again."
End If
_________________________________________
This seems to work fine, except for the fact that I cannot perform a sort. My gridview allows for sorting...
<asp:GridView ID="GridView1" runat="server" BackColor="White"
BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px" CellPadding="4"
AllowSorting="True" >
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<RowStyle BackColor="White" ForeColor="#330099" />
<Columns>
<asp:ButtonField ButtonType="Button" Text="Expand Details" />
</Columns>
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<AlternatingRowStyle BackColor="#99CCFF" />
</asp:GridView>
...and I'm handling the sorting in the code behind...
Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewSortEventArgs) Handles GridView1.Sorting
Dim oldExpression As String = GridView1.SortExpression
Dim newExpression As String = e.SortExpression
If (oldexpression.IndexOf(newExpression) < 0) Then
If (oldexpression.Length > 0) Then
e.SortExpression = newExpression & "," & oldexpression
Else
e.SortExpression = newExpression
End If
Else
e.SortExpression = oldExpression
End If
End Sub
...Why is this not working?