while update i have error
my source code is
<div id="dvGrid">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
Font-Names = "Arial" Font-Size = "11pt" BackColor="White"
AlternatingRowStyle-BackColor = "#C2D69B" HeaderStyle-BackColor = "pink"
ShowFooter="true" onrowediting="EditCustomer"
onrowcancelingedit="CancelEdit"
onrowupdating="UpdateCustomer">
<Columns>
<asp:TemplateField HeaderText="Name" ItemStyle-Width = "5px">
<ItemTemplate>
<asp:Label ID="lblname" runat="server" Text="<%#bind('Name') %>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txbna" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BillNo">
<ItemTemplate>
<asp:Label ID="lblbillno" runat="server" Text="<%# bind('BillNo') %>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txnbno" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BillDate">
<ItemTemplate>
<asp:Label ID="lbldatebil" runat="server" Text="<%#bind('BillDate' )%>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtbildate" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemTemplate>
<asp:Label ID="lblladrss" runat="server" Text="<%#bind('Address') %>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtadrsse" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Phone">
<ItemTemplate>
<asp:Label ID="lblbinpho" runat="server" Text="<%#bind('Phone') %>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtphnebin" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="EmailId">
<ItemTemplate>
<asp:Label ID="lblemiid" runat="server" Text="<%#bind('EmailId') %>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtemidl" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Supplierfor">
<ItemTemplate>
<asp:Label ID="lblsuplerfor" runat="server" Text="<%#bind('Supplierfor') %>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtsupfor" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Brand">
<ItemTemplate>
<asp:Label ID="lblbrdn" runat="server" Text="<%#bind('Brand') %>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtbnd" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<%-- <asp:TemplateField HeaderText="Billingrate">
<ItemTemplate>
<asp:Label ID="lbbigent" runat="server" Text="<%#bind('Billingrate') %>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtbingnnt" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="vat">
<ItemTemplate>
<asp:Label ID="lbvvat" runat="server" Text="<%#bind('vat') %>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txvaatb" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="discount">
<ItemTemplate>
<asp:Label ID="lbdisun" runat="server" Text="<%#bind('discount') %>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtdiscnt" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="total">
<ItemTemplate>
<asp:Label ID="lbtolot" runat="server" Text="<%#bind('total') %>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txttoool" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="percentage">
<ItemTemplate>
<asp:Label ID="lblpercng" runat="server" Text="<%#bind('percentage') %>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtpecntge" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="amount">
<ItemTemplate>
<asp:Label ID="lbamt" runat="server" Text="<%#bind('amount') %>"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtamnut" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
--%> <asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkRemove" runat="server" CommandArgument = '<%# Eval("Name")%>' OnClientClick = "return confirm('Do you want to delete?')"
Text = "Delete" OnClick = "DeleteCustomer"> </asp:LinkButton>
</ItemTemplate>
<FooterTemplate>
<asp:Button ID="btnAdd" runat="server" Text="Add" OnClick = "AddNewCustomer" />
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Columns><AlternatingRowStyle BackColor="#C2D69B" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID = "GridView1" />
</Triggers>
</asp:UpdatePanel>
</div>
my code is
protected void UpdateCustomer(object sender, GridViewUpdateEventArgs e)
{
string nm = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblname")).Text;
string BNo = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txnbno")).Text;
//string BNo = Convert.ToInt32(Bo)
string bdate = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtbildate")).Text;
string adre = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtadrsse")).Text;
string phn = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtphnebin")).Text;
string emil = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtemidl")).Text;
string supfr = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtsupfor")).Text;
string bbd = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtbnd")).Text;
//string bigt = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtbingnnt")).Text;
//string vatt = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txvaatb")).Text;
//string bdiste = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtdiscnt")).Text;
//string tool = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txttoool")).Text;
//string pentg = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtpecntge")).Text;
//string txtamt = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtamnut")).Text;
SqlConnection con = new SqlConnection(strConnString);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.Text;
// cmd.CommandText = "update suplerrate set BillNo=@BillNo," + "BillDate=@BillDate," + "Address=@Address, " + " Phone=@Phone ," + " EmailId=@EmailId," + "Supplierfor=@Supplierfor," + "Brand=@Brand," + "Billingrate=@Billingrate," + "vat=@vat," + "discount=@discount," + "total=@total," + "percentage=@percentage," + "amount=@amount where Name=@Name;" +
cmd.CommandText = "update suplerrate set BillNo=@BillNo," + "BillDate=@BillDate," + "Address=@Address, " + " Phone=@Phone ," + " EmailId=@EmailId," + "Supplierfor=@Supplierfor," + "Brand=@Brand where Name=@Name;" +
"select Name, BillNo,BillDate, Address,Phone,EmailId,Supplierfor,Brand from suplerrate";
// "select Name, BillNo,BillDate, Address,Phone,EmailId,Supplierfor,Brand,Billingrate,vat,discount,total,percentage,amount from suplerrate";
cmd.Parameters.Add("@Name", SqlDbType.VarChar).Value = nm;
cmd.Parameters.Add("@BillNo", SqlDbType.Int).Value = BNo;
cmd.Parameters.Add("@BillDate", SqlDbType.VarChar).Value = bdate;
cmd.Parameters.Add("@Address", SqlDbType.VarChar).Value = adre;
cmd.Parameters.Add("@Phone", SqlDbType.BigInt).Value = phn;
cmd.Parameters.Add("@EmailId", SqlDbType.VarChar).Value = emil;
cmd.Parameters.Add("@Supplierfor", SqlDbType.VarChar).Value = supfr;
cmd.Parameters.Add("@Brand", SqlDbType.VarChar).Value = bbd;
//cmd.Parameters.Add("@vat", SqlDbType.Float).Value = vatt;
//cmd.Parameters.Add("@discount", SqlDbType.Float).Value = bdiste;
//cmd.Parameters.Add("@total", SqlDbType.Float).Value = tool;
//cmd.Parameters.Add("@percentage", SqlDbType.Float).Value = pentg;
//cmd.Parameters.Add("@amount", SqlDbType.Float).Value = txtamt;
GridView1.EditIndex = -1;
GridView1.DataSource = GetData(cmd);
GridView1.DataBind();
}
my error is
An exception of type 'System.NullReferenceException' occurred in App_Web_ll8dodpz.dll but was not handled in user code
Additional information: Object reference not set to an instance of an object.
it show this line
string BNo = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txnbno")).Text;
my sql table is
CREATE TABLE [dbo].[suplerrate](
[Name] [varchar](max) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[BillNo] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[BillDate] [varchar](50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Address] [varchar](90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Phone] [bigint] NULL,
[EmailId] [varchar](90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Supplierfor] [varchar](90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Brand] [varchar](90) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[Billingrate] [float] NULL,
[vat] [float] NULL,
[discount] [float] NULL,
[total] [float] NULL,
[percentage] [float] NULL,
[amount] [float] NULL
) ON [PRIMARY]