
正文
GridView中给DropDownList动态绑定数据,及选择列表值后自动更新数据库
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
protected void sgvFile1_RowDataBound(object sender, GridViewRowEventArgs e)
{
DropDownList ddlAM = ((DropDownList)e.Row.FindControl("ddlAM"));
ddlAM.SelectedIndexChanged += new EventHandler(ddlAM_SelectedIndexChanged);
ddlAM.SelectedIndex = -;
ddlAM.Items.FindByValue(labAM.Text).Selected = true; }
protected void ddlAM_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList ddlAM = (DropDownList)sender;
string i = ddlAM.ID.Substring(ddlAM.ID.LastIndexOf("ddlAM") + , ddlAM.ID.Length - );
bool flage = false;
GridViewRow row = (GridViewRow)ddlAM.NamingContainer;
Label labAMPersonID = (Label)row.FindControl("labAMPersonID" + i); try
{
UpdateKaoQin(labAMPersonID.Text, ddlAM.SelectedValue);
}
catch
{
ScriptManager.RegisterClientScriptBlock(UpdatePanel1, typeof(UpdatePanel), "result", "alert('修改失败!');", true);
}
}






