我现在的问题是,我想在DataGrid的每一行中添加一个下拉菜单,这个下拉菜单在每一行都是一样的。
用户在选择下载菜单之后,确认,获得下拉菜单的值,并修改相应的记录!
谢谢兄弟们了。
本人asp.net功力是在浅薄,想了很长时间都没能解决。
希望看看你们的实现源码。谢谢了!!
http://www.cnblogs.com/lovecherry/archive/2005/05/25/125525.html
先绑定此datagrid
......
this.datagrid1.DataBind();
先求取要填充此下拉框的数据集
sql = "select id,name from table";
DataTable mytab = .....
循环此控件,求取下拉框
for(int i=0;i<this.datagrid1.Items.Count;i++)
{
DropDownList mydown = (DropDownList)this.datagrid1.Items[i].FindControl("你下拉框ID");
mydown.DataSource = mytab;
mydown.DataTextField = "name";
mydown.DataValueField = "id";
mydown.DataBind();
}
这样就可以了.
不过
使用DataGrid动态绑定DropDownList
http://dev.csdn.net/develop/article/26/26590.shtm
html:
====================================
<asp:TemplateColumn HeaderText="地区">
<HeaderStyle Wrap="False"></HeaderStyle>
<ItemStyle Wrap="False"></ItemStyle>
<ItemTemplate>
<asp:Label id=lblArea runat="server" Text=<%# DataBinder.Eval(Container, "DataItem.AreaDes") %>>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddlArea" runat="server"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
cs:
====================================
if (e.Item.ItemType == ListItemType.EditItem)
{
DropDownList ddlArea=(DropDownList)e.Item.FindControl("ddlArea");
//bound ddlArea
SqlConnection myConnection = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
SqlCommand myCommand = new SqlCommand("sp_AreaList", myConnection);
// Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure;
// Execute the command
myConnection.Open();
SqlDataReader result = myCommand.ExecuteReader(CommandBehavior.CloseConnection);
ddlArea.DataSource=result;
ddlArea.DataTextField="AreaDes";
ddlArea.DataValueField="AreaID";
ddlArea.DataBind();
result.Close();
}
用模板列,
右键属性生成器.加模板列,完成.
右键编缉模板列在ItemTemplate
下加DropDownList
在Page_Load里加
foreach(DataGridItem dataGridItem in DataGrid1.Items)
{
DropDownList ddff1=(DropDownList)dataGridItem.FindControl("DropDownList的名");
给ddff1加数据源.
绑定.
}