while update i have error
my source code is
Font-Names = "Arial" Font-Size = "11pt" BackColor="White"
AlternatingRowStyle-BackColor = "#C2D69B" HeaderStyle-BackColor = "pink"
ShowFooter="true" onrowediting="EditCustomer"
onrowcancelingedit="CancelEdit"
onrowupdating="UpdateCustomer">
<%--
--%>
Text = "Delete" OnClick = "DeleteCustomer">
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]
6 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.

Khan Abrar AhmedPosted Jul 8, 2014, 3:57 AM
protected void UpdateCustomer(object sender, GridViewUpdateEventArgs e)
{
string nm = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblname")).Text;
string BNo = ((TextBox)GridView1.FooterRow.FindControl("txnbno")).Text;
//string BNo = Convert.ToInt32(Bo)
string bdate = ((TextBox)GridView1.FooterRow.FindControl("txtbildate")).Text;
string adre = ((TextBox)GridView1.FooterRow.FindControl("txtadrsse")).Text;
string phn = ((TextBox)GridView1.FooterRow.FindControl("txtphnebin")).Text;
string emil = ((TextBox)GridView1.FooterRow.FindControl("txtemidl")).Text;
string supfr = ((TextBox)GridView1.FooterRow.FindControl("txtsupfor")).Text;
string bbd = ((TextBox)GridView1.FooterRow.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();
}
Khan Abrar AhmedPosted Jul 6, 2014, 3:20 AM
BNo=((TextBox)GridView1.FooterRow[e.RowIndex].FindControl("txnbno")).Text;
and any text box u are using in Footer uhave to use FooterRow[e.RowIndex]. for finding the control and value.
selvi subramanianPosted Jul 4, 2014, 7:31 AM
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.
Khan Abrar AhmedPosted Jul 4, 2014, 6:55 AM
BNo = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txnbno")).Text;
Server Error in '/bramandam site' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0029: Cannot implicitly convert type 'System.Web.UI.WebControls.TextBox' to 'string' Source Error: Line 401: Line 402: string nm = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblname")).Text; Line 403: string BNo = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txnbno")); Line 404: string bdate = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtbildate")).Text; Line 405: string adre = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtadrsse")).Text; Source File: d:\bramandam site\stockentry.aspx.cs Line: 403 Show Detailed Compiler Output: Show Complete Compilation Source: Version Information: Microsoft .NET Framework Version:2.0.50727.4984; ASP.NET Version:2.0.50727.4971
selvi subramanianPosted Jul 4, 2014, 6:39 AM
Server Error in '/bramandam site' Application. Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0029: Cannot implicitly convert type 'System.Web.UI.WebControls.TextBox' to 'string' Source Error: Line 401: Line 402: string nm = ((Label)GridView1.Rows[e.RowIndex].FindControl("lblname")).Text; Line 403: string BNo = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txnbno")); Line 404: string bdate = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtbildate")).Text; Line 405: string adre = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txtadrsse")).Text; Source File: d:\bramandam site\stockentry.aspx.cs Line: 403 Show Detailed Compiler Output: Show Complete Compilation Source: Version Information: Microsoft .NET Framework Version:2.0.50727.4984; ASP.NET Version:2.0.50727.4971
Khan Abrar AhmedPosted Jul 4, 2014, 6:23 AM
if i m not wrong the issue is in below code because when you are trying to find the control value it is not finding, because it is in footer templeten
try like this when you are fetching the data.