473,857 Members | 2,117 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 3381
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
3158
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
2067
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
16347
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
7022
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
4499
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
8543
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
1965
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
2050
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
1353
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
9923
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
9767
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
11082
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10394
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
7104
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5774
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...
1
4592
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4190
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.