比如显示时为:
姓名 部门
张三 销售一部
李四 销售二部 进入编辑时,要求部门用DropDownList进行选择并且进入编辑模式时使当前部门项被选中
最好能有详细的代码,谢谢了~在线等待~~
姓名 部门
张三 销售一部
李四 销售二部 进入编辑时,要求部门用DropDownList进行选择并且进入编辑模式时使当前部门项被选中
最好能有详细的代码,谢谢了~在线等待~~
解决方案 »
- C#问题求解。。
- (int)67.5 是不是等于Convert.toInt32(67.5)?
- 小弟恳求在 VS2003里面实现一个功能~~~~~~~~~~~急.在线等!!!
- winform datagrid question
- 如何后台代码设置DataGridView的某行某列
- 想做一个C# Web版 HTML编辑器控件,但是没什么头绪。大家帮忙提下解决办法。
- 微信公众平台获取JSON的解析
- C#语言的问题求解
- 请把你的手给我!解决马上结贴。
- 大家来讨论,请各位大哥们指点迷津,详情请看。。。。。。。。。。
- 如何获得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";