GridView中 DropDownList的选定项的问题。。。。。。。。。。。 在线等
在GridView1的一摸板列的HeaderRow中我放了一个 DropDownList1来控制 GridView1每页显示的记录数,DDL_SelectedIndexChanged的时候,记录数会变,可DropDownList的选定项总是不变:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList DDL = (DropDownList)GridView1.HeaderRow.FindControl( "DropDownList1 ");
if (DDL != null)
{
int count = 5;
string num = DDL.SelectedItem.Value;
if (num != "all ")
{
count = int.Parse(num);
}
else
{
DataSet ds = (DataSet)GridView1.DataSource;
if (ds != null)
{
count = ds.Tables[0].Rows.Count;
}
}
GridView1.PageSize = count;
ListItem LI = (ListItem)DDL.Items.FindByText(num);
if (LI != null)
{
LI.Selected = true;
}
}
}
Text value
DDL : 5