比如显示时为:
姓名 部门
张三 销售一部
李四 销售二部 进入编辑时,要求部门用DropDownList进行选择并且进入编辑模式时使当前部门项被选中
最好能有详细的代码,谢谢了~在线等待~~
姓名 部门
张三 销售一部
李四 销售二部 进入编辑时,要求部门用DropDownList进行选择并且进入编辑模式时使当前部门项被选中
最好能有详细的代码,谢谢了~在线等待~~
解决方案 »
- 程序后台处理时button 禁用的属性,progressBar怎么做呀……
- 怎么学习编程这门技术,才更容易掌握呢?
- 帮我看看 我写对CheckBoxList是否选中的判断怎么横为假?
- C#中线程调用的方法如何才能传递参数?
- 请教一个关于数据库插入的问题
- 遇到一个超奇怪的问题,求高人解答
- 你来连连,反正我是没办法连
- 关于web的滚动条。求救,谢谢。分数不够可以在加。帮顶有分,解决问题就给分
- ActiveX控件在IE8下不能显示出来
- [求助]问一个关于远程文件确定的菜鸟问题,怎么判断远程文件和文件夹??
- 如何获得datagridviewComboboxCell的选中项的value和text值?
- 将方法改为泛型方法
再编辑模板列
在模板列的ItemTemplate里添加一个dropdownlist 进行双重绑定(绑定一个数据源,再editdatabing绑定部门ID)
这样就可以了
{
if(e.Row.RowType== DataControlRowType.DataRow)
{
DropDownList DropDownList1 = (DropDownList)e.Row.FindControl("DropDownList1"); DropDownList1.DataSource = GetTableForDropdownList();
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "PartMent";
DropDownList1.DataBind();
}
} private DataTable GetTableForDropdownList()
{
DataTable dt = new DataTable();
dt.Columns.Add("Name", typeof(string));
dt.Columns.Add("PartMent", typeof(string)); DataRow row = dt.NewRow();
row["Name"] = "张三";
row["PartMent"] = "销售一部";
dt.Rows.Add(row); DataRow row1 = dt.NewRow();
row1["Name"] = "李四";
row1["PartMent"] = "销售二部";
dt.Rows.Add(row1); return dt;
}html:<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="AAAAA">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</form>
</body>
还有就是我在RowDataBound事件中,怎么也获取不到当前需要绑定DROPDOWNLIST的值
string wcm_level = this.GridView_Manager.DataKeys[e.Row.RowIndex]["wcm_level"].ToString();
要报错..
{
string id = GridView1.DataKeys[e.Row.RowIndex].Value.ToString();
}得有循环,那么多行呢,它不知道是哪行
{
string id = GridView1.DataKeys[gr.RowIndex].Value.ToString();
}
在加个附值的语句就可以了protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType== DataControlRowType.DataRow)
{
DropDownList DropDownList1 = (DropDownList)e.Row.FindControl("DropDownList1"); DropDownList1.DataSource = GetTableForDropdownList();
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "PartMent";
DropDownList1.DataBind();//取得XXX 部门资料
DropDownList1.SelectValue = "XXXX";
}
}
DropDownList1.SelectValue = "XXXX";