drop down list and 'All'

J

JohnE

I have a gridview with paging and a pagesize of 10. Users are able to able
to set a higher pagesize value from the ddl outside the gridview. The items
in the ddl were placed there thru the Items collection property. I used 10,
20, 30 ... to
100. The Items has text and value as the same (ie 10/10, 20/20, and so on
to 100). Below is the code that is used and it all works. Now the users are
looking to have 'All' as part of the items in addition to the numbers. That
way they can select 'All' and show a one page gridview which is one big long
list of rows. In the code below, if the first line is removed then the user
gets their wish. My question is if what is in the ddl are numbers converting
to ints, how is the 'All' looked at when the text and value are All/All in
the Items collection? What is the best approach to have the numbers and
'All' as an available selection?
Thanks.

protected void ddlNumberPerPage_SelectedIndexChanged(object sender,
EventArgs e)
{
GridView1.PageSize = Convert.ToInt32(ddlNumberPerPage.SelectedValue);
GridView1.DataSource = bindgrid();
GridView1.DataBind();
}
 
P

Patrice

If using All/All you'll try to convert text to an integer and you'll get an
exception. So youll have to test for this value and do whatever you want.

Or you could perhaps just use a high value (possibly Int32.MaxValue) as the
value for All. This way you don't have to handle anything special (basically
"All" means that you want as much records as possible on a single page.
 
J

JohnE

Mark Rae said:
if (ddlNumberPerPage.SelectedText == "All")
{
GridView1.AllowPaging = false;
}
else
{
GridView1.AllowPaging = true;
GridView1.PageSize = Convert.ToInt32(ddlNumberPerPage.SelectedValue);
}

As an aside (and since you're a beginner) you really should get into the
habit of using meaningful names for your objects and variables rather than
GridView1 etc...

The If was the culprit I had problem with. Ended up using Text instead of
SelectedText as it was not available in the intellisense list and Text was.
It works fine now.
Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top