dropdownlist question

  • Thread starter Thread starter JohnE
  • Start date Start date
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
 
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
 
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
 
Alexey Smirnov 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'
 
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
 
Back
Top