报错:
无法将类型为“System.Web.UI.LiteralControl”的对象强制转换为类型“System.Web.UI.WebControls.TextBox”
html:
<asp:TemplateField HeaderText="状态">
<ItemTemplate>
<%# Eval("status")%>
</ItemTemplate>
<EditItemTemplate>
<asp:HiddenField ID="HDFXueli" runat="server" Value='<%# Eval("status") %>' />
<asp:DropDownList ID="DDLXueli" runat="server" Width="90px" />
</EditItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
aspx.cs是这样的写的.
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
String strConnection = ConfigurationSettings.AppSettings["ConnectionString"];
SqlConnection myConnection = new SqlConnection(strConnection);
SqlCommand cm = new SqlCommand("updatelogin", myConnection);
cm.CommandType = CommandType.StoredProcedure;
cm.Connection.Open();
int id;
string username, userkind,wentilist,wenti,prio,status;
id = int.Parse(GridView1.Rows[e.RowIndex].
Cells[0].Text);
username = ((TextBox)GridView1.Rows[e.RowIndex].
Cells[1].Controls[0]).Text;
userkind = ((TextBox)GridView1.Rows[e.RowIndex].
Cells[2].Controls[0]).Text;
wenti= ((TextBox)GridView1.Rows[e.RowIndex].
Cells[3].Controls[0]).Text;
wentilist= ((TextBox)GridView1.Rows[e.RowIndex].
Cells[4].Controls[0]).Text;
status= ((TextBox)GridView1.Rows[e.RowIndex].
Cells[5].Controls[0]).Text;
cm.Parameters.Add(new SqlParameter("@id", id));
cm.Parameters.Add(new SqlParameter("@username", username));
cm.Parameters.Add(new SqlParameter("@userkind", userkind));
cm.Parameters.Add(new SqlParameter("@wenti", wenti));
cm.Parameters.Add(new SqlParameter("@wentilist", wentilist));
cm.Parameters.Add(new SqlParameter("@status", status ));
cm.ExecuteNonQuery();
GridView1.EditIndex = -1;
Bindgridview();
}