|
已经完成下拉列表相关示例,ChangeSet:76628
-增加示例grid/grid_edit_dropdownlist.aspx和grid/grid_edit_dropdownlist2.aspx,演示如何在后台绑定Grid中下拉列表数据。
这样为Grid中的下拉列表绑定数据:
- protected void Grid1_RowDataBound(object sender, ExtAspNet.GridRowEventArgs e)
- {
- System.Web.UI.WebControls.DropDownList ddlGender = (System.Web.UI.WebControls.DropDownList)Grid1.Rows[e.RowIndex].FindControl("ddlGender");
- List<string> genderList = new List<string>();
- genderList.Add("男");
- genderList.Add("女");
- ddlGender.DataSource = genderList;
- ddlGender.DataBind();
- DataRowView row = e.DataItem as DataRowView;
- int gender = Convert.ToInt32(row["Gender"]);
- if (gender == 1)
- {
- ddlGender.SelectedValue = "男";
- }
- else
- {
- ddlGender.SelectedValue = "女";
- }
- }
复制代码
这样获取用户提交的下拉列表的值:
- protected void Button1_Click(object sender, EventArgs e)
- {
- StringBuilder sb = new StringBuilder();
- sb.Append("<table style="width:350px;"><tr><th>编号</th><th>姓名</th><th>用户输入的性别</th></tr>");
- for (int i = 0, count = Grid1.Rows.Count; i < count; i++)
- {
- sb.Append("<tr>");
- object[] rowDataKeys = Grid1.DataKeys[i];
- sb.AppendFormat("<td>{0}</td>", rowDataKeys[0]);
- sb.AppendFormat("<td>{0}</td>", rowDataKeys[1]);
- GridRow row = Grid1.Rows[i];
- System.Web.UI.WebControls.DropDownList ddlGender = (System.Web.UI.WebControls.DropDownList)row.FindControl("ddlGender");
- sb.AppendFormat("<td>{0}</td>", ddlGender.SelectedValue);
- sb.Append("<tr>");
- }
- sb.Append("</table>");
- labResult.Text = sb.ToString();
- }
复制代码
|
|