VS03 DataGrid 中有一DropDownList 控件。急!
要它在选择了后。点了DataGrid自带的UpdateCommand后触发事件
部分代码如下:
<asp:TemplateColumn HeaderText="是否锁定">
<ItemTemplate>
<asp:DropDownList id="ddl1" runat="server" Enabled="False">
<asp:ListItem Value="1">开通</asp:ListItem>
<asp:ListItem Value="2">锁定</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddl2" runat="server">
<asp:ListItem Value="1">开通</asp:ListItem>
<asp:ListItem Value="2">锁定</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
后台代码如下:
private void DataGrid1_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
//int x=Convert.ToInt32(((DropDownList)(e.Item.FindControl("ddl2"))).);
//int x=0;
int x1=0;
string x=((DropDownList)e.Item.FindControl("ddl2")).SelectedValue;
if(Convert.ToInt32(x)==1)
{
x1=1;
}
else
{
x1=2;
}
int y=SetcsFdInfoUtility.EditFdStateByID(x1,Convert.ToInt32(e.Item.Cells[0].Text));
if(y==0)
{
Response.Write("<script>alert('更新失败!');</script>");
return;
}
else
{
Response.Write("<script>alert('更新成功!');</script>");
this.BindData();
return;
}
}