473,606 Members | 2,885 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Gridview Sorting and Paging problem

In my web design, I display records from a SQL DataBase according to
some filters
the GridView is defined with select commands and selest parameters

however, I also want to display all records in the database when the
user press a "View All" button.

In this case, I need to change the select comand and clear the
parameters. And I did this in the button_click() event. the GridView
can display desired results when I press the "View All" button,

However, when I click the header to sort, the GridView gone away, like
redered without any data. Press the button again, can show, but not
sorted.

i think it is because of the select command.

when sorting, the SqlDataSource.S elect command is the one I
declaratively defined one, not the new one I assigned in the
button_Click() event.

So what Can I do with this to make the select command changed to the
one i want?

Apr 10 '06 #1
5 3372
Hi,

I can't see your code so I suggest you an advise for this situation. The
best way for doing this is using GridView's paging and sorting mechanisms
but giving a data source is in code behind files. If you make like this you
control your code easily and not having problems like this. Also I suggest
you to use a DataView objects for Data Source. If you don't know how to do
it as again and I will post a code.

Have a nice work,

Aytaç ÖZAY
Software Developer

"yefei" <we************ *@hotmail.com> wrote in message
news:11******** **************@ v46g2000cwv.goo glegroups.com.. .
In my web design, I display records from a SQL DataBase according to
some filters
the GridView is defined with select commands and selest parameters

however, I also want to display all records in the database when the
user press a "View All" button.

In this case, I need to change the select comand and clear the
parameters. And I did this in the button_click() event. the GridView
can display desired results when I press the "View All" button,

However, when I click the header to sort, the GridView gone away, like
redered without any data. Press the button again, can show, but not
sorted.

i think it is because of the select command.

when sorting, the SqlDataSource.S elect command is the one I
declaratively defined one, not the new one I assigned in the
button_Click() event.

So what Can I do with this to make the select command changed to the
one i want?

Apr 10 '06 #2
Thanks very much
i try to define a gridview and a SqlDataSource without connectionstrin g
and select command like this
<asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue"
AllowSorting="T rue"
CellPadding="4" DataSourceID="S qlDataSource1"
ForeColor="#333 333" GridLines="None " EmptyDataText=" No Data Record" >
<FooterStyle BackColor="#990 000" Font-Bold="True"
ForeColor="Whit e" />
<RowStyle BackColor="#FFF BD6" ForeColor="#333 333" />
<SelectedRowSty le BackColor="#FFC C66" Font-Bold="True"
ForeColor="Navy " />
<PagerStyle BackColor="#FFC C66" ForeColor="#333 333"
HorizontalAlign ="Center" />
<HeaderStyle BackColor="#990 000" Font-Bold="True"
ForeColor="Whit e" />
<AlternatingRow Style BackColor="Whit e" />
</asp:GridView>
<asp:Button ID="Button1" runat="server" OnClick="Button 1_Click"
Text="Button" />
<asp:SqlDataSou rce ID="SqlDataSour ce1"
runat="server"> </asp:SqlDataSour ce>

and a little operation in the .cs file
protected void Button1_Click(o bject sender, EventArgs e)
{
SqlDataSource1. ConnectionStrin g =
ConfigurationMa nager.Connectio nStrings["ServiceConnect ionString"].ToString();
SqlDataSource1. SelectCommand = "select * from [tblService]";
}

it displays the gridview when i click the button. However, when I click
the column header or the page index to change, the gridview displays,
and the "No Data Record" is displayed, like no data in the data source.

I also tried to define the gridview with connection string and select
command,. but change the select command when the button is clicked. The
same problem came out.

I wrote a line to write the select commad when in Sorting or
PageIndexChangi ng event, it display the original one defined in the
..aspx file, instead of the one changed to in .aspx.cs file in the
Button_Click() event.

what could be the reason for this?
I am very appreciated for your help.

Apr 11 '06 #3
the one i defined above, i enabled the sorting and paging but not
define the sort expression explicitly in the code file

Apr 11 '06 #4
i found out that no matter how you define the gridview, when you change
the select command in the event of some controls, when sorting and
pageIndexChangi ng, the gridview is load again, and the select command
is set back to the original one.

Apr 11 '06 #5
Hi,

Maybe your SqlDataSource can not bound to your GridView when you click a
column header or a page index. I advise you not to to use a Toolbox
Components for this action, if you coded this, you have no problem occured I
think.

Have a good work,

Aytaç ÖZAY
Software Engineer

"yefei" <we************ *@hotmail.com> wrote in message
news:11******** **************@ z34g2000cwc.goo glegroups.com.. .
Thanks very much
i try to define a gridview and a SqlDataSource without connectionstrin g
and select command like this
<asp:GridView ID="GridView1" runat="server" AllowPaging="Tr ue"
AllowSorting="T rue"
CellPadding="4" DataSourceID="S qlDataSource1"
ForeColor="#333 333" GridLines="None " EmptyDataText=" No Data Record" >
<FooterStyle BackColor="#990 000" Font-Bold="True"
ForeColor="Whit e" />
<RowStyle BackColor="#FFF BD6" ForeColor="#333 333" />
<SelectedRowSty le BackColor="#FFC C66" Font-Bold="True"
ForeColor="Navy " />
<PagerStyle BackColor="#FFC C66" ForeColor="#333 333"
HorizontalAlign ="Center" />
<HeaderStyle BackColor="#990 000" Font-Bold="True"
ForeColor="Whit e" />
<AlternatingRow Style BackColor="Whit e" />
</asp:GridView>
<asp:Button ID="Button1" runat="server" OnClick="Button 1_Click"
Text="Button" />
<asp:SqlDataSou rce ID="SqlDataSour ce1"
runat="server"> </asp:SqlDataSour ce>

and a little operation in the .cs file
protected void Button1_Click(o bject sender, EventArgs e)
{
SqlDataSource1. ConnectionStrin g =
ConfigurationMa nager.Connectio nStrings["ServiceConnect ionString"].ToString();
SqlDataSource1. SelectCommand = "select * from [tblService]";
}

it displays the gridview when i click the button. However, when I click
the column header or the page index to change, the gridview displays,
and the "No Data Record" is displayed, like no data in the data source.

I also tried to define the gridview with connection string and select
command,. but change the select command when the button is clicked. The
same problem came out.

I wrote a line to write the select commad when in Sorting or
PageIndexChangi ng event, it display the original one defined in the
.aspx file, instead of the one changed to in .aspx.cs file in the
Button_Click() event.

what could be the reason for this?
I am very appreciated for your help.





Apr 14 '06 #6

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

Similar topics

2
3151
by: Hajime Kusakabe | last post by:
Hi. I have created a datagrid (datagrid1) without any columns on a aspx page. Then aspx.vb adds columns from a database. It is somthing like this .... ================================== Dim myBoundColumnEntryBy As New BoundColumn() myBoundColumnEntryBy.DataField = "Entry By" myBoundColumnEntryBy.SortExpression = "Entry By"
0
2058
by: Christian Hofmann | last post by:
Hello, I am using .Net Framework 2.0 Beta and for testing firefox. I disabled JavaScript in Firefox and now the gridview sorting and paging does not work. Evenery link is calling, for example, javascript:__doPostBack('GridView1$ctl01$ctl01',''). But this does not work when javascript is disabled. What can I do that ASP.Net will not use javascript? Maybe a normal link?
2
16330
by: | last post by:
Hello, I have a GridView in my ASP.NET 2.0 application that performs the paging feature perfect when I have it bound to a data source. But now I have it bound to a dataset and the paging feature will not work. When I try to use paging I get this error: The GridView 'gvResults' fired event PageIndexChanging which wasn't handled.
1
7003
by: tfsmag | last post by:
Hello, I have a function that returns a dynamically created gridview. This works fine, however it does not seem to be able to maintain state when adding sorting or paging to the gridview. Does anyone have any idea how to get this to work? below is the code. Please bear in mind that the function is actually located in a seperate class file from the page that actually returns the grid. ---code for function that returns the grid, this is...
2
4484
by: WebBuilder451 | last post by:
I have a grid view and filter it based on an event from another control. I set the filter and it works fine, but when i page it reverts back to the full set of data from the datasource. How can i maintain the filtered set? -- thanks (as always) some day i''m gona pay this forum back for all the help i''m getting kes
8
8525
by: AG | last post by:
ASP.NET 2.0, VS 2005 I have a gridview with paging enabled, bound to an objectdatasource. Both were dropped on to the page and configured via the wizards. Basically working as expected. The gridview's databind method is apparently called when the page is loaded as I have no code calling the databind method. How can I keep the gridview from databinding automatically and control it myself?
1
1949
by: John A Grandy | last post by:
In regard to a GridView that must support searching, filtering, sorting, and paging ... There is a tradeoff in performing the sorting and paging in the database versus to creating a CLR sort expression and allowing the GridView to perform the sorting and paging. How do people feel about each option for (1) simple sorts (alphabetical, compound alphabetical)
1
2037
by: suganya | last post by:
I have displayed the data from the DB to the GridView made a column in the GridView as HyperLink allowed paging by setting the Allow Paging Property to "True". By clicking on the page no link I have to view other records. For that I have given the coding as protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; GridView1.DataBind(); } ...
0
1338
by: =?Utf-8?B?R3JlZw==?= | last post by:
I've been playing around with the GridView and for the most part am able to achieve most of what I need to. I am having just one problem and that's with the Sorting and Paging options. If I use a <asp:sqlDataSourcesorting and paging work fine, but when I popluate the GridView via a DataSet via Code-Behind, the sorting and paging do not work at all. I don't want to use sqlDataSource because my DataSets will be creating using Stored...
0
8031
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
7962
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
8443
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...
1
8107
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6792
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
5971
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
3945
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
3989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1565
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.