原理,在初始GridView控件时将事件绑定到每row的dorpdownlist控件上...
执行事件.
protected
void
GridView1_RowDataBound(
object
sender, GridViewRowEventArgs e)
... {
if (e.Row.RowType == DataControlRowType.DataRow)
...{
DropDownList ddl = e.Row.FindControl("ddl_province") as DropDownList;
if (ddl != null)
...{
ddl.AutoPostBack = true;
ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
}
}
}
protected void ddl_SelectedIndexChanged( object sender, System.EventArgs e)
... {
DropDownList Drp=(DropDownList)sender;
string region = Drp.SelectedItem.Value;
Response.Write(region);
DropDownList ddl = sender as DropDownList;
if (ddl != null)
...{
TableCell cell = ddl.Parent as TableCell;
if (cell != null)
...{
Label lbl = cell.FindControl("Label1") as Label;
Response.Write("</br>" + lbl.Text);
}
}
... {
if (e.Row.RowType == DataControlRowType.DataRow)
...{
DropDownList ddl = e.Row.FindControl("ddl_province") as DropDownList;
if (ddl != null)
...{
ddl.AutoPostBack = true;
ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);
}
}
}
protected void ddl_SelectedIndexChanged( object sender, System.EventArgs e)
... {
DropDownList Drp=(DropDownList)sender;
string region = Drp.SelectedItem.Value;
Response.Write(region);
DropDownList ddl = sender as DropDownList;
if (ddl != null)
...{
TableCell cell = ddl.Parent as TableCell;
if (cell != null)
...{
Label lbl = cell.FindControl("Label1") as Label;
Response.Write("</br>" + lbl.Text);
}
}