我的代码中有以下行:
cmd.Parameters.Add("@priority", SqlDbType.VarChar).Value = ((DropDownList)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).SelectedValue;
但是当我运行它时,我收到以下错误:
Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.DropDownList'.
知道为什么会这样吗?
GridView 的相关部分是这样的:
<asp:TemplateField HeaderText="Priority">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("priority") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server"
SelectedValue='<%# Bind("priority") %>'>
<asp:ListItem Value="0">Low</asp:ListItem>
<asp:ListItem Value="1">Normal</asp:ListItem>
<asp:ListItem Value="2">High</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>