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

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.Select 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 3348
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.googlegr oups.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.Select 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 connectionstring
and select command like this
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True"
CellPadding="4" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None" EmptyDataText="No Data Record" >
<FooterStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True"
ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
<asp:SqlDataSource ID="SqlDataSource1"
runat="server"></asp:SqlDataSource>

and a little operation in the .cs file
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource1.ConnectionString =
ConfigurationManager.ConnectionStrings["ServiceConnectionString"].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
PageIndexChanging 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
pageIndexChanging, 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.googlegr oups.com...
Thanks very much
i try to define a gridview and a SqlDataSource without connectionstring
and select command like this
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True"
CellPadding="4" DataSourceID="SqlDataSource1"
ForeColor="#333333" GridLines="None" EmptyDataText="No Data Record" >
<FooterStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True"
ForeColor="Navy" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333"
HorizontalAlign="Center" />
<HeaderStyle BackColor="#990000" Font-Bold="True"
ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
Text="Button" />
<asp:SqlDataSource ID="SqlDataSource1"
runat="server"></asp:SqlDataSource>

and a little operation in the .cs file
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataSource1.ConnectionString =
ConfigurationManager.ConnectionStrings["ServiceConnectionString"].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
PageIndexChanging 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
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...
0
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,...
2
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...
1
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...
2
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...
8
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...
1
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...
1
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...
0
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
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
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...

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.