c# datagrid 更新数据

来源:百度知道 编辑:UC知道 时间:2024/05/22 01:56:37
我在datagrid模版列中加入
<ItemTemplate>
<asp:DropDownList id="DropDownList2" runat="server"></asp:DropDownList>
<asp:Button id="Button2" runat="server" Width="27px" Text="修改" BackColor="White"></asp:Button>
</ItemTemplate>
我想点击按钮修改下拉菜单选中的内容,该如何做啊。高手指点(DropDownList已经绑定好)
我不是要修改下拉菜单,是要在点击旁边修改按钮时把下拉菜单中选中的项更新到数据。按钮和下拉菜单都在datagird中

SqlDataReader r;
Button2_Click(object sender,System.EventArgs e)
{
r=cmd.ExecuteReader();
DropDownList2.DataSource=r;
DropDownList2.DataBind();//如果已经绑定数据源的话只用这句就可以了
r.Close();
DropDownList2.Items.Add(new ListItem("--No selected--","0"));
DropDownList2.SelectedIndex=DropDownList2.Items.Count-1;
}
上面的说得对,要修改就得重新赋值
DropDownList2.Items.Clear();
DropDownList2.Add(new ListItem("/*SelectedItem.Text*/","/*SelectedItem.Value*/"));
//....以后一项一项的田加

修改下拉菜单,你还真会想.直接把下拉菜单清空下拉,然后重新赋值!~