HI
I have grid view in my page below is my code
<asp:TemplateField ItemStyle-Width = "100px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:Label ID="lblmob" runat="server" Text='<%# Eval("Tell")%>' CssClass="lblmobV"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width = "15px" ItemStyle-HorizontalAlign="Center">
<ItemTemplate>
<asp:LinkButton ID="lnkRemove2" runat="server" CommandArgument = '<%# Eval("ID")%>'
OnClientClick = "return confirm("DO you want insert this data?")"
Text = "✔ " OnClick = "insertCustomer" CssClass="linkGV1"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
and Behind code
protected void insertCustomer(object sender, EventArgs e)
{
LinkButton lnkRemove2 = (LinkButton)sender;
SqlCommand cmd = new SqlCommand("insertvariz", _cn);
cmd.CommandType = CommandType.StoredProcedure;
string Mobile = ((Label)GridView1.FindControl("lblMob")).Text;
cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = lnkRemove2.CommandArgument;
cmd.Parameters.Add("@Tell", SqlDbType.VarChar).Value = Mobile;
GridView1.DataSource = GetData(cmd);
GridView1.DataBind();
BindData();
}
I want when users click on Linkbutton it insert data from gridview into Variz Table in database
but when I click on link button below error happen
Server Error in '/behtop website' 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 377: SqlCommand cmd = new SqlCommand("insertvariz", _cn); Line 378: cmd.CommandType = CommandType.StoredProcedure; Line 379: string Mobile = ((Label)GridView1.FindControl("lblMob")).Text; Line 380: Line 381: cmd.Parameters.Add("@ID", SqlDbType.VarChar).Value = lnkRemove2.CommandArgument;
|
Why this happen?
Bestregards.