放置在GridView中的Dropdownlist,获取GridView的行号


GridView 或 DataGrid控件上的模板列,放置DropDownList控件,通过改变DropDownList控件的值,来改变GridView中该行的其它信息

  具体的实现办法:

  Code

1protected void Drpd_SelectedIndexChanged(object sender, EventArgs e)
2  {
3
4    DropDownList drp = sender as DropDownList; // 触发事件的 DropDownList
5    GridViewRow row = drp.NamingContainer as GridViewRow; // GridView 当前行 即时在dropdownlist所在容器里 就是行的信息    
6    row.Style.Add(HtmlTextWriterStyle.BackgroundColor, drp.SelectedValue);
7    Response.Write(row.RowIndex+1);//获取dropdownlist中选定行的行号.
8        //Response.Write(String.Format("选中第 {0} 行", row.RowIndex + 1));
9     DropDownList ddlClass = (DropDownList)sender;
10     string ClassID = ddlClass.SelectedValue.ToString();//获取Dropdownlist中选定值
11     //Response.Write(ClassID);
12}
13

  在dropdownlist的SelectedIndexChanged事件下获取行号


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3