473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Sorting in Gridview

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="<%$ ConnectionStrings:Pubs %>" />
</form>
</body>
</html>
Feb 1 '07 #1
0 1009

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: ck388 | last post by:
For some reason when I enable the callback feature of the gridview I still get a page refresh, that is it seems like there is a postback that occurs, not a callback which is just supposed to update...
2
by: Arjen | last post by:
Hi, I get this error message when sorting a gridview: The GridView 'GridView1' fired event Sorting which wasn't handled What do I need to do? Thanks!
4
by: samb | last post by:
When I use manual databinding to a GridView control, as bellow. 'Retrive a DataSet from database Dim ds As DataSet = uda.GetUsers(conectionString) 'gvUsers - The GridView gvUsers.DataSource...
4
by: kurt sune | last post by:
I have a an aspx page with a gridview. The gridview is data bound to a generic list of custom classes. The gridview's DataSource is thus not set. Now I want to add sorting to it. So I create...
0
by: jobo | last post by:
Hey there, I'm having a problem getting sorting to work. Here's what the GridView looks like: "server" ID="updt1" Mode="Conditional">
2
by: sivagururaja | last post by:
Hi All, How can i sorting the Gridview Columns via the code behind. When i tried to sorting the column it doesn't work. SqlConnection con = new SqlConnection("Connection string");...
4
by: =?Utf-8?B?R2VyaGFyZA==?= | last post by:
I have a vb.net 2.0 app that is loading a GridView with a DataSource that is returned from a function. The definitions in the function are: Dim ReportDS As DataSet = New DataSet Dim...
3
by: =?Utf-8?B?YmJkb2J1ZGR5?= | last post by:
I have a question that maybe somebody can help me out. I have a gridview that is bound to a sqltable, and I have created two template columns. I am having problems getting the sorting to work....
0
by: =?Utf-8?B?QVZM?= | last post by:
Hi, I've a requirement in which I want to use the custom sorting.. I mean I've a dropdown with sortable column names and when the user selects the particular column from dropdown , I need to sort...
1
by: dorandoran | last post by:
The sort on the childgrid is not working; nothing happens when I click on the each column header for sort. (I followed Satay's sample: http://www.codeproject.com/KB/aspnet/EditNestedGridView.aspx)...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.