G
Guest
Hi
I want to sort with this datagrid without using the sql datasource straight
from the page. I actually use a different datasource for this but show this
to simplify the problem. How do i sort since i got the paging tuned on?
thanks
B
<%@ Page Language="VB" %>
<%@import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub GridView1_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
GridView1.DataSource = SqlDataSource1
GridView1.DataBind()
End Sub
Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs)
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.GridViewPageEventArgs)
End Sub
Protected Sub GridView1_Sorted(ByVal sender As Object, ByVal e As
System.EventArgs)
End Sub
Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewSortEventArgs)
End Sub
</script>
<html>
<head id="Head1" runat="server">
<title>Updating Data Using GridView</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" AllowSorting="true" AllowPaging="true"
Runat="server"
AutoGenerateEditButton="true"
AutoGenerateColumns="False" OnLoad="GridView1_Load"
OnSorted="GridView1_Sorted" OnSorting="GridView1_Sorting"
OnPageIndexChanging="GridView1_PageIndexChanging">
<Columns>
<asp:BoundField ReadOnly="true" HeaderText="ID" DataField="au_id"
SortExpression="au_id" />
<asp:BoundField HeaderText="Last Name" DataField="au_lname"
SortExpression="au_lname" />
<asp:BoundField HeaderText="First Name" DataField="au_fname"
SortExpression="au_fname" />
<asp:BoundField HeaderText="Phone" DataField="phone"
SortExpression="phone" />
<asp:BoundField HeaderText="Address" DataField="address"
SortExpression="address" />
<asp:BoundField HeaderText="City" DataField="city"
SortExpression="city" />
<asp:BoundField HeaderText="State" DataField="state"
SortExpression="state" />
<asp:BoundField HeaderText="Zip Code" DataField="zip"
SortExpression="zip" />
<asp:CheckBoxField HeaderText="Contract" SortExpression="contract"
DataField="contract" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
SelectCommand="SELECT [au_id], [au_lname], [au_fname], [phone], [address],
[city], [state], [zip], [contract] FROM [authors]"
UpdateCommand="UPDATE [authors] SET [au_lname] = @au_lname,
[au_fname] = @au_fname, [phone] = @phone, [address] = @address, [city] =
@city, [state] = @state, [zip] = @zip, [contract] = @contract WHERE [au_id] =
@au_id"
ConnectionString="<%$ ConnectionStringsubs %>" />
</form>
</body>
</html>
I want to sort with this datagrid without using the sql datasource straight
from the page. I actually use a different datasource for this but show this
to simplify the problem. How do i sort since i got the paging tuned on?
thanks
B
<%@ Page Language="VB" %>
<%@import Namespace="System.Data" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub GridView1_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
GridView1.DataSource = SqlDataSource1
GridView1.DataBind()
End Sub
Protected Sub GridView1_PageIndexChanged(ByVal sender As Object, ByVal e
As System.EventArgs)
End Sub
Protected Sub GridView1_PageIndexChanging(ByVal sender As Object, ByVal
e As System.Web.UI.WebControls.GridViewPageEventArgs)
End Sub
Protected Sub GridView1_Sorted(ByVal sender As Object, ByVal e As
System.EventArgs)
End Sub
Protected Sub GridView1_Sorting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewSortEventArgs)
End Sub
</script>
<html>
<head id="Head1" runat="server">
<title>Updating Data Using GridView</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="GridView1" AllowSorting="true" AllowPaging="true"
Runat="server"
AutoGenerateEditButton="true"
AutoGenerateColumns="False" OnLoad="GridView1_Load"
OnSorted="GridView1_Sorted" OnSorting="GridView1_Sorting"
OnPageIndexChanging="GridView1_PageIndexChanging">
<Columns>
<asp:BoundField ReadOnly="true" HeaderText="ID" DataField="au_id"
SortExpression="au_id" />
<asp:BoundField HeaderText="Last Name" DataField="au_lname"
SortExpression="au_lname" />
<asp:BoundField HeaderText="First Name" DataField="au_fname"
SortExpression="au_fname" />
<asp:BoundField HeaderText="Phone" DataField="phone"
SortExpression="phone" />
<asp:BoundField HeaderText="Address" DataField="address"
SortExpression="address" />
<asp:BoundField HeaderText="City" DataField="city"
SortExpression="city" />
<asp:BoundField HeaderText="State" DataField="state"
SortExpression="state" />
<asp:BoundField HeaderText="Zip Code" DataField="zip"
SortExpression="zip" />
<asp:CheckBoxField HeaderText="Contract" SortExpression="contract"
DataField="contract" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" Runat="server"
SelectCommand="SELECT [au_id], [au_lname], [au_fname], [phone], [address],
[city], [state], [zip], [contract] FROM [authors]"
UpdateCommand="UPDATE [authors] SET [au_lname] = @au_lname,
[au_fname] = @au_fname, [phone] = @phone, [address] = @address, [city] =
@city, [state] = @state, [zip] = @zip, [contract] = @contract WHERE [au_id] =
@au_id"
ConnectionString="<%$ ConnectionStringsubs %>" />
</form>
</body>
</html>