我正在gridview中更新一些数据,没有编译错误,但是当我运行程序时,异常
对象引用未设置为对象的实例
出现。请帮帮我
.aspx
代码:
<asp:GridView ID="GridView3" runat="server" DataKeyNames="assessid" AutoGenerateColumns="False" ShowFooter=true
AllowPaging="True" CellPadding="4" ForeColor="#333333" GridLines="None"
OnRowEditing="editing" OnRowCommand="inserted" onrowupdating="updating" OnRowDeleting="deleted" OnRowCancelingEdit="canceling"
>
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="ID" Visible="true">
<ItemTemplate>
<asp:Literal ID="id7" runat="server" Text='<%#Eval("assessid") %>' >
</asp:Literal>
</ItemTemplate>
</asp:TemplateField>
</column>
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" />
</gridview>
.aspx.cs
代码:
public void updating(object sender,GridViewUpdateEventArgs e)
{
assessdal d1 = new assessdal();
string ID = GridView3.DataKeys[e.RowIndex].Value.ToString();
GridViewRow row = GridView3.Rows[e.RowIndex];
TextBox l = (TextBox)row.FindControl("id1");
TextBox box = (TextBox)row.FindControl("id2");
d1.insertoption1(ID, l.Text, box.Text);
}
public void insertoption1(string id,string s, string w)
{
SqlConnection con = dbconnect.GetConnection();
SqlCommand cmd = new SqlCommand(" update assessmenttest set option1=s,description=w where assessid=id");
cmd.ExecuteNonQuery();
}
答案 0 :(得分:0)
您必须在查找控件中使用文本框ID。
希望这能解决您的问题