Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a problem in my app development. can anyone help please.

Source Error:


Line 34: String Payrollnumber =
Line 35: DataList1.DataKeys[e.Item.ItemIndex].ToString();
Line 36: String FirstName =
Line 37: ((TextBox)e.Item.FindControl("FirstName")).Text;
Line 38: String MiddleName =

source Code
C#
protected void DataList1_UpdateCommand(object source,
       DataListCommandEventArgs e)
   {
       String Payrollnumber =
            DataList1.DataKeys[e.Item.ItemIndex].ToString();
       String FirstName =
            ((TextBox)e.Item.FindControl("FirstName")).Text;
       String MiddleName =
            ((TextBox)e.Item.FindControl("MiddleName")).Text;
       String LastName =
            ((TextBox)e.Item.FindControl("LastName")).Text;
       String Designation =
            ((TextBox)e.Item.FindControl("Designation")).Text;
       SqlDataSource1.UpdateParameters["PayrollNumber"].DefaultValue
           = Payrollnumber;
       SqlDataSource1.UpdateParameters["FirstName"].DefaultValue
           = FirstName;
       SqlDataSource1.UpdateParameters["MiddleName"].DefaultValue
           = MiddleName;
       SqlDataSource1.UpdateParameters["LastName"].DefaultValue
           = LastName;
       SqlDataSource1.UpdateParameters["Designation"].DefaultValue
           = Designation;
       SqlDataSource1.Update();

       DataList1.EditItemIndex = -1;
       DataList1.DataBind();
   }
Posted
Comments
Karthik Harve 12-Mar-13 6:07am    
did you debugged and check which object is going null ? because there so many objects which can throw this error. so, debugging is the only option for this.
José Amílcar Casimiro 12-Mar-13 6:12am    
If your code is crashing here String FirstName = ((TextBox)e.Item.FindControl("FirstName")).Text, then
most probably e.Item.FindControl("FirstName") is returning null, and the object can not be found.
You will need to debug the code.

1 solution

String FirstName ="";

TextBox txtfirstname= (TextBox)e.Item.FindControl("FirstName");

if(txtfirstname!=null){
FirstName = txtfirstname.Text;
}

You can do like this.But debugg the code ,I Think controls are not finding properly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900