473,401 Members | 2,139 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,401 software developers and data experts.

GridView and View Top 5/View All

I want to have a button to view top 5 and toggle to view all on my gridview.

Can this be done using paging? I don't want to show page 1, 2, 3. Just the
top 5 or all.

Or am I going to have to postback and change my query? If I do that I will
also lose my current sorting. Any suggestions?
Jan 18 '07 #1
5 1974
your could setup ur gridview so that it has an empty pagerTemplate -so that
the page numbers are not shown.

then set the event handler for your "top 5" button to enable paging on the
gridview and set the pagesize to 5.

and have ur event handler for 'all' to disable paging.

so you shouldnt have to requery your data (it should remain in the
gridview's viewstate)

good luck
Jan 18 '07 #2
When I click the button it works and I can see all the rows, but I don't get
the right sort order:

This is on the page load, so the sorting
DataTable statetable = StateDataSet.Tables[0];
GridView2.DataSource = statetable;
GridView2.DataBind();

Here's by button click function

protected void Button1_Click(object sender, EventArgs e)
{
GridView2.AllowPaging = false;
GridView2.DataBind();
Button1.Visible = false;
Button2.Visible = true;
}

"XOR" <XO*@discussions.microsoft.comwrote in message
news:12**********************************@microsof t.com...
your could setup ur gridview so that it has an empty pagerTemplate -so
that
the page numbers are not shown.

then set the event handler for your "top 5" button to enable paging on the
gridview and set the pagesize to 5.

and have ur event handler for 'all' to disable paging.

so you shouldnt have to requery your data (it should remain in the
gridview's viewstate)

good luck

Feb 14 '07 #3
On Feb 14, 3:22 pm, "Cindy Lee" <cindy...@hotmail.comwrote:
When I click the button it works and I can see all the rows, but I don't get
the right sort order:

This is on the page load, so the sorting

DataTable statetable = StateDataSet.Tables[0];
GridView2.DataSource = statetable;
GridView2.DataBind();

Here's by button click function

protected void Button1_Click(object sender, EventArgs e)
{
GridView2.AllowPaging = false;
GridView2.DataBind();
Button1.Visible = false;
Button2.Visible = true;
}
Cindy,

Bind to a view to sort your grid items:

StateDataSet.Tables[0].DefaultView.Sort = "FieldNameHere ASC"; //or
DESC
GridView2.DataSource = StateDataSet.Tables[0].DefaultView;
GridView2.DataBind();

Now, to display top 5, you can either do a postback, filter your view
and rebind, or try some javascript to hide the rest
of the grid items:

<script language="javascript" type="text/javascript">
function filterGrid ()
{
var myForm = document.forms["FormNameHere"];
var table = document.getElementById("GridNameHere");
if (table == null)
return;

//hide the rest of grid item except for the top 5 (grid index
starts at 0)
for (var r = 5; r < table.rows.length; r++)
{
table.rows[r].style.display = 'none';
}
}
</script>

HTH,
Quoc Linh

Feb 14 '07 #4
I generally do my sorting in a dataview

DataTable statetable = StateDataSet.Tables[0];
DataView dv = new DataView(statetable);
dv.sort = "name of field to sort by";
GridView2.DataSource = dv;
GridView2.DataBind();

Feb 14 '07 #5
Well I want to use the gridview sorting so I don't have to worry about all
the different parameters.
I also don't want to have to re-query everything.

The sorting works on my gridview just fine with my sorting functions. But
it's just when I click the button, it doesn't keep the old settings. Is
there a way to take the current gridview and make that the new datasource or
remember the last sort?

"Quoc Linh" <le********@yahoo.comwrote in message
news:11**********************@h3g2000cwc.googlegro ups.com...
On Feb 14, 3:22 pm, "Cindy Lee" <cindy...@hotmail.comwrote:
When I click the button it works and I can see all the rows, but I don't
get
the right sort order:

This is on the page load, so the sorting

DataTable statetable = StateDataSet.Tables[0];
GridView2.DataSource = statetable;
GridView2.DataBind();

Here's by button click function

protected void Button1_Click(object sender, EventArgs e)
{
GridView2.AllowPaging = false;
GridView2.DataBind();
Button1.Visible = false;
Button2.Visible = true;
}

Cindy,

Bind to a view to sort your grid items:

StateDataSet.Tables[0].DefaultView.Sort = "FieldNameHere ASC"; //or
DESC
GridView2.DataSource = StateDataSet.Tables[0].DefaultView;
GridView2.DataBind();

Now, to display top 5, you can either do a postback, filter your view
and rebind, or try some javascript to hide the rest
of the grid items:

<script language="javascript" type="text/javascript">
function filterGrid ()
{
var myForm = document.forms["FormNameHere"];
var table = document.getElementById("GridNameHere");
if (table == null)
return;

//hide the rest of grid item except for the top 5 (grid index
starts at 0)
for (var r = 5; r < table.rows.length; r++)
{
table.rows[r].style.display = 'none';
}
}
</script>

HTH,
Quoc Linh

Feb 15 '07 #6

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

Similar topics

5
by: sutphinwb | last post by:
Hi - This could be a simple question. When I relate two tables in a datasetet, how do I get that relation to show up in a GridView? The only way I've done it, is to create a separate table in the...
0
by: John Smith | last post by:
ASP.Net 2.0 / C# / IIS 6 I have 2 pages. The master page consists of a tabbed menu created using the Menu and MultiView controls. Something like this: ...
3
by: BartMan | last post by:
Greetings, I have a gridview which is sitting on a multi view control (witin a view), and it is bound to a dataset which I dynamically apply to the control within asp.net page. The problem is...
0
by: John Smith | last post by:
If anyone can help, I would very muchly appreciate it. I have a main page that uses the .net 2.0 menu control with the multiview controls as the menu choices. This works fine. One of the menu...
1
by: syl | last post by:
Hello I am trying to create a "easy to use" gridview with filters (dropdownlist in headers), sorting...and much more.... In order to do that, i prefer to use a objectdatasource (ODS) beacause...
4
by: Tomasz Jastrzebski | last post by:
Hello Everyone, I have a GridView control bound to a plain DataTable object. AutoGenerateEditButton is set to true, Edit button gets displayed, and RowEditing event fires as expected.
12
by: Cindy Lee | last post by:
When I do a sorta on 1 table, then the other table goes back to the original order. What can I set so, it keeps the order of the other current gridview's order. I set all the gridview values...
3
by: Dariusz Tomon | last post by:
Hello, I have GridView in EditItem Template of DetailsView (in normal - read-only mode there is a label). When I'm in edit mode I can select one item from GridView. The main problem is that as...
7
by: Joe Kovac | last post by:
Hi! I have one page with a GridView. Their I can select one item and edit this item on an own page within a DetailsView. After updating the entry I want the user to be able to get back to the...
4
by: svgeorge | last post by:
I NEED TO COLLECT FROM THE GRIDVIEW(DATASELECTED) IN TO A TABLE(SelectedPayment) -------------------------------------------------------------------------------- How TO COLLECT THE ROWS...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
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
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...
0
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,...

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.