473,698 Members | 2,179 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview without datasource

1 New Member
Hi
I am wokrin on a website where i hav a grid view displaying data from an SQL table accordin to the customer chosen in the dropdown list in the update panel.

This works fine but i am havin trouble with the sorting when i click on the column name.Also paging does not work.The following are the functions i used:

Expand|Select|Wrap|Line Numbers
  1. private string GridViewSortDirection
  2.         {
  3.         get { return ViewState["SortDirection"] as string ?? "ASC"; }
  4.         set { ViewState["SortDirection"] = value; }
  5.         }
  6.         private string GridViewSortExpression
  7.         {
  8.         get { return ViewState["SortExpression"] as string ?? string.Empty; }
  9.         set { ViewState["SortExpression"] = value; }
  10.         }
  11.         private string GetSortDirection()
  12.         {
  13.        switch (GridViewSortDirection)
  14.             {
  15.                 case "ASC":
  16.                 GridViewSortDirection = "DESC";
  17.                 break;
  18.                 case "DESC":
  19.                 GridViewSortDirection = "ASC";
  20.                 break;
  21.             }
  22.              return GridViewSortDirection;
  23.         }
  24.         protected void GridViewOrders_PageIndexChanging(object sender, GridViewPageEventArgs e)
  25.         {
  26.         GridViewOrders.DataSource = SortDataTable(GridViewOrders.DataSource as DataTable, true);
  27.         GridViewOrders.PageIndex = e.NewPageIndex;
  28.         GridViewOrders.DataBind();
  29.         if (GridViewOrders.Rows.Count == 0)
  30.         {
  31.             NoData.Visible = true;
  32.         }
  33.         else
  34.         {
  35.             NoData.Visible = false;
  36.         }
  37.         }
  38.         protected DataView SortDataTable(DataTable dataTable, bool isPageIndexChanging)
  39.         {
  40.         if (dataTable != null)
  41.             {
  42.                 DataView dataView = new DataView(dataTable);
  43.                if (GridViewSortExpression != string.Empty)
  44.                 {
  45.                    if (isPageIndexChanging)
  46.                     {
  47.                        dataView.Sort = string.Format("{0} {1}", GridViewSortExpression, GridViewSortDirection);
  48.                    }
  49.                    else
  50.                     {
  51.                        dataView.Sort = string.Format("{0} {1}", GridViewSortExpression, GetSortDirection());
  52.                    }
  53.                }
  54.                return dataView;
  55.            }
  56.            else
  57.             {
  58.                return new DataView();
  59.            }
  60.        }
  61.        protected void GridViewOrders_Sorting(object sender, GridViewSortEventArgs e)
  62.         {
  63.            GridViewSortExpression = e.SortExpression;
  64.            int pageIndex = GridViewOrders.PageIndex;
  65.            GridViewOrders.DataSource = SortDataTable(myDataSet.Tables[0] as DataTable, false);
  66.            GridViewOrders.DataBind();
  67.            GridViewOrders.PageIndex = pageIndex;
  68.        }
  69.  
  70. and i have mentioned abt the functions in the gridview as follows:
  71.  
  72. <asp:GridView ID="GridViewOrders" runat="server" AutoGenerateColumns="False" Width="900px"
  73.                 AllowSorting="True" AllowPaging="True" PageSize="20" PagerSettings-NextPageText="Next" OnPageIndexChanging="GridViewOrders_PageIndexChanging"  
  74. OnSorting="GridViewOrders_Sorting" >
PLease help me with this.I am a beginner so i would need detailed solution.Thanks in advance.
Dec 4 '07 #1
0 1253

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

Similar topics

7
14806
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
4
13486
by: Jim Katz | last post by:
I have an application that updates a strongly typed data set at run time. I'd like to dynamically create a table that connects to a run time data table. For displaying the data, this works well. I just set the GridView.DataSource once, and call DataBind(); I'd like to drive the application from the GridView control, by including command buttons that allow editing of the data. Starting out simple, I have a DataTable with a boolean...
1
3526
by: jmdolinger | last post by:
Hi all, I'm a newbie to Atlas (and recently ASP.NET) after coming from a long Java background, also have done quite a bit with an Ajax.NET/ASP.NET 1.1 project, but it was basically all javascript, nothing really having to do with ASP.NET... I'm attempting to put together an application that consists of several GridView controls each bound to some xml data. Each table exists in its own update panel. The two effects I'm going for are:
0
1516
by: trint | last post by:
I hope I can explain this clearly enough to get help. I have three gridviews that need to work from each other to display like a java verticle menu (just in the way it appears). GridView1 is fine with this code: <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" DataKeyNames="id" autogenerateselectbutton="True" autogeneratecolumns="False"
0
2002
by: Don Miller | last post by:
Here is an example of what I believe is a bug in ASP.NET 2.0 GridView paging without postbacks (or at least not documented how to fix it). Once the GridView is displayed, clicking on any of the paging tools causes the GridView to completely disappear! This happens when either DataSets or DataTables are used (it doesn't work at all for DataReaders because they don't support paging apparently). If you remove the...
4
2724
by: Don Miller | last post by:
This is a repost of a reproducible problem/bug with GridView with dynamic SQL and binding. Is there a better ASP.NET newsgroup I should post to where MS techs or MVPs take an interest in such problems? Thanks. Here is an example of what I believe is a bug in ASP.NET 2.0 GridView paging without postbacks (or at least not documented how to fix it). Once the GridView is displayed, clicking on any of the paging tools causes the
4
9784
by: mohaaron | last post by:
This seems like it should be simple to do but for some reason I have been unable to make it work. I would like to databind a SqlDataSource to a GridView during the click event of a button. This sounds easy but the next requirement is that the GridView is editable. So I have included the SelectCommand and the UpdateCommand on the SqlDataSource to allow the GridView to be editable. I have now been able to get the GridView to display data...
0
1527
by: Sobin Thomas | last post by:
Hi All, How can I bind the Gridview control to Sql Datasource control on a button click(I see majority of the articles binding datasource at page load) I need to enable the paging and sorting of the Gridview control also .Actually I am able to bind the sql datasource control to the Gridview on button Click but on clicking the GridView for paging or sorting , the Gridview vanishes!! In short, I want to bind the GridView control to a...
1
2016
by: Sobin Thomas | last post by:
Hi All, How can I bind the Gridview control to Sql Datasource control on a button click(I see majority of the articles binding datasource at page load) I need to enable the paging and sorting of the Gridview control also .Actually I am able to bind the sql datasource control to the Gridview on button Click but on clicking the GridView for paging or sorting , the Gridview vanishes!! In short, I want to bind the GridView control to a...
3
5238
by: Peter | last post by:
I have a GridView which is populated by List<ofObjects> Does anyone have example of how to sort the columns of this GridView? I have found examples without DataSourceControl but these use DataTable, I am using List of Objects. Here's one example: http://ryanolshan.com/technology/gridview-without-datasourcecontrol-datasource/
0
8674
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8604
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9028
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7728
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4369
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4619
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2330
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.