DropDownList没有CommandName属性,所以不能用ItemCommand事件,不过你可以在DataGrid的模板列中加入的DropDownList控件(aspx):
<asp:TemplateColumn HeaderText="车辆情况">
<ItemTemplate>
<asp:DropDownList id="carinfolist" runat="server" OnSelectedIndexChanged="carinfolist_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem Value="1" Selected="True">正常</asp:ListItem>
<asp:ListItem Value="0">停用</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
private void LiqDatagrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)

...{
if ((e.Item.ItemType == ListItemType.Item)||(e.Item.ItemType == ListItemType.AlternatingItem))

...{
string StrPower = e.Item.Cells[6].Text.Trim(); // 用隐藏列取出数据
DropDownList drpcarinfo = (DropDownList)e.Item.Cells[5].FindControl("carinfolist");
for(int i=0;i<drpcarinfo.Items.Count;i++)

...{
if(StrPower.Equals(drpcarinfo.Items[i].Value))

...{
drpcarinfo.Items[i].Selected = true;
}
else

...{
drpcarinfo.Items[i].Selected=false;
}
}
}
}
protected void carinfolist_SelectedIndexChanged(object sender, System.EventArgs e)

...{
string droplist = ((DropDownList)sender).SelectedValue;
DropDownList ddl = (DropDownList)sender;
TableCell cell = (TableCell)ddl.Parent;
DataGridItem item = (DataGridItem)cell.Parent;
new components.DBCarInfo().carInfonew_Update(Convert.ToInt32(item.Cells[4].Text),droplist);
Response.Write("<script>alert('!');</script>");
}









注意:OnSelectedIndexChanged事件及AutoPostBack="True"
一、DropDownList的动态绑定,只需在DataGrid1_ItemDataBound的事件中,取出数值进行匹配.代码如下:
























二、触发DataGrid中DropDownList的事件









