473,387 Members | 1,504 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,387 software developers and data experts.

Problem with sorting the gridview

I'm currently using Gridview to display some data from SQL however having problem with allowing users to sort the data. Here's what I got:

Expand|Select|Wrap|Line Numbers
  1.  <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
  2.                                         ConnectionString="<%$ ConnectionStrings:ServiceNowDB %>" 
  3.                                         ProviderName="<%$ ConnectionStrings:ServiceNowDB.ProviderName %>" 
  4.  
  5.  
  6.                                         SelectCommand="SELECT [number], [request_item], [assigned_to], [state], [subscriber], [room_num], [request_type], [deploy_type], [due_date], [item_sysid], [task_sysid] FROM [sc_tasks_updated] WHERE ([state] NOT LIKE '%' + ? + '%')">
  7.                                         <SelectParameters>
  8.                                             <asp:Parameter DefaultValue="Closed" Name="state" Type="String" />
  9.                                         </SelectParameters>
  10.                                     </asp:SqlDataSource>
  11.                                     <br />
  12.                                     <asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
  13.                                         AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource1" 
  14.                                         ForeColor="#333333" GridLines="None" 
  15.                                         EnableSortingAndPagingCallbacks="false">
  16.                                         <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
  17.                                         <Columns>
  18.                                             <asp:BoundField DataField="number" HeaderText="Number" 
  19.                                                 SortExpression="number" ItemStyle-HorizontalAlign="Center">
  20. <ItemStyle HorizontalAlign="Center"></ItemStyle>
  21.                                             </asp:BoundField>
  22.  
  23. ..... more asp:BoundFields.....
  24.  
  25. </Columns>
  26. </asp:GridView>
  27.  
  28.  
code behind:

on page_load, I do some data manipulation like this:

Expand|Select|Wrap|Line Numbers
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. string takslink = "http://www.domain.com/task.list?id=2343";
  4.  
  5. thisRow.Cells[0].Text = "<a href=\"" + tasklink + "\">" + thisRow.Cells[0].Text + "</a>";
  6.  
  7. thisRow.Cells[4].Text = thisRow.Cells[4].Text.Replace(":", "");
  8.  
  9. }
  10.  
When user click on the column title to sort, the page is posted back with the same set of data but all the data manipulation I did on page_load is lost.

Any help is appreciated. I'm a beginner.

Thanks
GQ
Nov 9 '10 #1
0 907

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Arjen | last post by:
Hi, I databind my gridview like this: GridView1.DataSource = Membership.GetAllUsers(); // asp.net 2.0 (MembershipUserCollection) GridView1.DataBind(); When I try to sort the gridview I get...
0
by: ferherra | last post by:
Hi, Hope someone can help... I databind my gridview (asp.net 2.0) like this: GridView1.DataSource = Membership.GetAllUsers(); (MembershipUserCollection) GridView1.DataBind(); In the...
2
by: Loading name... | last post by:
Hey asp.net 2.0 I have a GridView on my webpage. This GridView's datasource is a SqlDataSource. The SqlDataSource returns 3 columns. Here is my problem: My GridView consist of 3 columns...
0
by: dba123 | last post by:
I cannot get the sorting to work. We're passing in a CodeGen value to the web controls: Parser Error Message: Databinding expressions are only supported on objects that have a DataBinding event....
3
by: Jeff | last post by:
Hey asp.net 2.0 In the source I posted below, there is a GridView (look at the bottom of the script): <asp:GridView ID="gvwOnline" runat="server"> </asp:GridView> I'm trying to assign a...
0
by: ccshine | last post by:
I have a Gridview populated with a DataTable that I store in the Session. I'm trying to sort the columns, but have only been able to get it to partially work. When I click on a header the first...
1
by: Will | last post by:
So I have a gridview with a column that has a drop down in that column. What I want to do is resort the gridview which is originally sorted by that column to be resorted based on what is selected...
1
by: Jeff | last post by:
ASP.NET 2.0 I've got problems with the right column in my GridView. The GridView consist of 2 columns, the problem column is the column on the right side. The problem is that it looks like...
4
by: DAnDA | last post by:
I have a Gridview Which as you know it was sorted by Ascending by default. Now i want Gridview to Sorting Descending On Load,,, i want somthing like Below: protected void Page_Load(object...
0
by: neelam26 | last post by:
Hi, I want to know if there is any way to add sort images (Up/Down) to a Column header when it is sorted. The gridview AutoGenerateColumns proerty is set to TRUE I don't get the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.