468,110 Members | 1,540 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,110 developers. It's quick & easy.

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 3149
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Hajime Kusakabe | last post: by
reply views Thread by Christian Hofmann | last post: by
1 post views Thread by tfsmag | last post: by
2 posts views Thread by WebBuilder451 | last post: by
8 posts views Thread by AG | last post: by
1 post views Thread by John A Grandy | last post: by
1 post views Thread by suganya | last post: by
reply views Thread by =?Utf-8?B?R3JlZw==?= | last post: by
1 post views Thread by didacticone | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.