GridView和下拉菜单DropDownList结合

时间:2018-09-28 11:42:27
【文件属性】:
文件名称:GridView和下拉菜单DropDownList结合
文件大小:66KB
文件格式:DOC
更新时间:2018-09-28 11:42:27
GridView DropDownList namespace Exercise1.DepMng { public partial class UserM2 : System.Web.UI.Page { Helper he = new Helper(); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Bind(); } } public void Bind() { string user_sql = "select * from User"; DataSet ds = he.GetDataSet(user_sql, "User"); GridView1.DataSource = ds; GridView1.DataKeyNames = new string[] { "UserID" }; GridView1.DataBind(); //设Θ?置? DropDownList默?认?值μ DropDownList ddl; for (int i = 0; i <= GridView1.Rows.Count - 1; i++) { DataRowView mydrv = ds.Tables[0].DefaultView[i]; ddl = (DropDownList)GridView1.Rows[i].FindControl("depList"); ddl.SelectedValue = ds.Tables[0].Rows[i]["DepId"].ToString(); ddl = (DropDownList)GridView1.Rows[i].FindControl("roleList"); ddl.SelectedValue = ds.Tables[0].Rows[i]["RId"].ToString(); } } public DataSet ddlbind() { string sql = "select * from Department"; DataSet ds = he.GetDataSet(sql, "Department"); return ds; }

网友评论

  • 正是我想要的资源,谢谢楼主分享。