dropdownlist question

J

JohnE

I have a gridview with paging and a pagesize of 20. Users would like to be
able to set a higher value. I placed a ddl outside the gridview and put
numbers into thru the property Items collection. I used 10, 20, 30 ... to
100. When the user changes the number in the ddl, I need to have the
pagesize go to that amt. The Items has text and value as the same. I am
struggling with getting it to work properly and seek assistance with it. So
if someone can walk me thru this, great. Links to sites are also good.
John
 
J

JohnE

Sorry, I forgot to paste in the code I had so far.

protected void ddlNumberPerPage_SelectedIndexChanged(object sender,
EventArgs e)
{
GridView1.PageSize = 40;
GridView1.DataSource = bindgrid();
GridView1.DataBind();
}

This works and gives me 40 rows per page. It is what to put in place of 40
is what is frustrating me.

Thanks.
John
 
G

Guest

Sorry, I forgot to paste in the code I had so far.

     protected void ddlNumberPerPage_SelectedIndexChanged(object sender,
EventArgs e)
    {
        GridView1.PageSize = 40;
        GridView1.DataSource = bindgrid();
        GridView1.DataBind();
    }

This works and gives me 40 rows per page.  It is what to put in place of 40
is what is frustrating me.

Thanks.
John





- Show quoted text -

Did you tried ddlNumberPerPage.SelectedValue?

// GridView1.PageSize = 40;
GridView1.PageSize = ddlNumberPerPage.SelectedValue
 
J

JohnE

Anon User said:
Did you tried ddlNumberPerPage.SelectedValue?

// GridView1.PageSize = 40;
GridView1.PageSize = ddlNumberPerPage.SelectedValue

Yes. I tried it and the red line appears under all of it. What is says is
'Cannot implicity converty type string to int'
 
J

JohnE

Mark Rae said:
That means exactly what it says - the SelectedValue property of a
DropDownList is a string but the PageSize property of a GridView expects an
integer...

So...

GridView1.PageSize = Convert.ToInt32(ddlNumberPerPage.SelectedValue);

That did it. I tried several other ways, of which none worked. Got
frustrated and went and had some ice cream. I might be working at this way
to much. I need a vacation.
Thanks again.
John
 

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

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,740
Latest member
JudsonFrie

Latest Threads

Top