急!GridView和下拉菜单DropDownList结合的问题,改变某一行DropDownList的值,数据库里的数据为什么不更
protectedvoidGridView1_SelectedIndexChanged(objectsender,EventArgse){DropDownListType...
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList Type = sender as DropDownList;
TableCell cell = (TableCell)Type.Parent;
GridViewRow item = (GridViewRow)cell.Parent;
string sqlstr = "Update assignment set LL='" + Type.SelectedValue + "' where ID='"+item.Cells[0].Text+"'";
sqlcon = new MySqlConnection(strCon);
sqlcom = new MySqlCommand(sqlstr, sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
//sqlcon.Close();
}
<asp:TemplateField HeaderText="LL">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSource='<%# ddlbind()%>' DataValueField="LL" DataTextField="LL" AutoPostBack="True">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
我的目的就是在gridview中,直接修改dropdownlist的值,能更新到数据库。 展开
{
DropDownList Type = sender as DropDownList;
TableCell cell = (TableCell)Type.Parent;
GridViewRow item = (GridViewRow)cell.Parent;
string sqlstr = "Update assignment set LL='" + Type.SelectedValue + "' where ID='"+item.Cells[0].Text+"'";
sqlcon = new MySqlConnection(strCon);
sqlcom = new MySqlCommand(sqlstr, sqlcon);
sqlcon.Open();
sqlcom.ExecuteNonQuery();
//sqlcon.Close();
}
<asp:TemplateField HeaderText="LL">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" DataSource='<%# ddlbind()%>' DataValueField="LL" DataTextField="LL" AutoPostBack="True">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
我的目的就是在gridview中,直接修改dropdownlist的值,能更新到数据库。 展开
2个回答
展开全部
1、GridView1_SelectedIndexChanged这个方法根本就进不去的
2、你可以把前台的下拉框改一下<asp:DropDownList ID="DropDownList1" runat="server" DataSource='<%# ddlbind()%>' DataValueField="LL" DataTextField="LL" AutoPostBack="True" OnSelectedIndexChanged=”方法名”>,然后在后台编写这个方法就好了
2、你可以把前台的下拉框改一下<asp:DropDownList ID="DropDownList1" runat="server" DataSource='<%# ddlbind()%>' DataValueField="LL" DataTextField="LL" AutoPostBack="True" OnSelectedIndexChanged=”方法名”>,然后在后台编写这个方法就好了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询