in a grid view me bind the data .if i click the update it throw the error like this
Server Error in '/bramandam site' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
Line 81: TextBox tfn = (TextBox)dv.FindControl("tsn");
Line 82: Label lb = ((Label)dv.FindControl("Label4"));
Line 83: string qry = "update section set sectionid='" + tbf.Text;
Line 84: qry += "',sectionname='" + tfn.Text;
Line 85: qry += "' where pk='" + lb.Text;
Source File: d:\jquery themes\bramandam site\Section.aspx.cs Line: 83
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Section.GridView1_RowUpdating(Object sender, GridViewUpdateEventArgs e) in d:\jquery themes\bramandam site\Section.aspx.cs:83
System.Web.UI.WebControls.GridView.OnRowUpdating(GridViewUpdateEventArgs e) +133
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +720
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +704
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +123
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565
Version Information: Microsoft .NET Framework Version:2.0.50727.4984; ASP.NET Version:2.0.50727.4971
if i click the update i need to throw the error edit and update the content
my gridview is
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="sectionid" onrowdeleting="GridView1_RowDeleting" onrowcommand="GridView1_RowCommand" onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating" BackColor="White" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px" CellPadding="3" GridLines="Horizontal">
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
<Columns>
<asp:TemplateField HeaderText="pk" Visible="False">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text="<%#bind('pk') %>"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SectionId">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text="<%#bind('sectionid') %>"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tss" runat="server" Text="<%#bind('sectionid') %>"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="SectionName">
<ItemTemplate>
<asp:Label ID="llb" runat="server" Text="<%#bind('sectionname') %>"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tsn" runat="server" Text="<%#bind('sectionname') %>"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:LinkButton ID="lbedit" runat="server" CommandArgument="<%#bind('sectionid') %>" CommandName="Edit">Edit</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Update">
<ItemTemplate>
<asp:LinkButton ID="lbupa" runat="server" CommandArgument="<%#bind('sectionid') %>" CommandName="Update">Update</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Delete">
<ItemTemplate>
<asp:LinkButton ID="lbdel" runat="server" CommandArgument="<%#bind('sectionid') %>" CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
<PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
<HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
<AlternatingRowStyle BackColor="#F7F7F7" />
</asp:GridView>
my gird view code is
private void details()
{
try
{
string qre = "select pk,sectionid,sectionname from section";
DataSet ds = new DataSet();
ds = gdv.GETDS(qre);
if (ds.Tables[0].Rows.Count != 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
else if (ds.Tables[0].Rows.Count == 0)
{
Lblll.Text = "There is Nosection in the List";
}
else
{
Lblll.Text = "There is No section in the List";
}
}
catch (Exception e)
{
throw e;
}
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
GridViewRow gd = GridView1.Rows[e.RowIndex];
string tem = ((LinkButton)gd.FindControl("lbdel")).CommandArgument.ToString();
gdv.Insert("delete section where sectionid='" + tem + "'");
details();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
details();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow dv = GridView1.Rows[e.RowIndex];
TextBox tbf = (TextBox)dv.FindControl("tss");
TextBox tfn = (TextBox)dv.FindControl("tsn");
Label lb = ((Label)dv.FindControl("Label4"));
string qry = "update section set sectionid='" + tbf.Text;
qry += "',sectionname='" + tfn.Text;
qry += "' where pk='" + lb.Text;
qry += "'";
gdv.Insert(qry);
GridView1.EditIndex = -1;
details();
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Edit")
{
string temp = Convert.ToString(e.CommandArgument);
}
else if (e.CommandName == "Update")
{
string temp = Convert.ToString(e.CommandArgument);
}
else if (e.CommandName == "Delete")
{
string temp = Convert.ToString(e.CommandArgument);
}
}