Click here to Skip to main content
15,921,169 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using C#,asp.net,server 2005 and visual studio 2005


my Gridview contains one row and 5 columns.

when the page load occurs i am filling gridview with null values..

now i change the values in the gridview(values of text boxes)...

now the problem is when i click on save button the values that were there when page load occured is saved into the database... i.e., null values..

but i want to save the updated values of textboxes
how to get the value of each column without using any of the event...



plz help me..

regards
karan
Posted
Comments
Orcun Iyigun 23-May-11 14:12pm    
in a for loop
for (int i = 0; i < GridViewName.Rows.Count; i++)
{
string var1 = GridViewName.Rows[i].Cells[0].Text;
string var2 = GridViewName.Rows[i].Cells[1].Text;
....
}
karan joshua 24-May-11 14:06pm    
ok .. thank you very much..

The problem is simple. As you said, you are filling the gridview with NULL values on page load, so when you click the save button, again the page load will be called and it will refill the gridview with NULL. You will have to make a check on page load to see if gridview already has value, it should not fill it back with NULL or something like that.

Hope that helps.
 
Share this answer
 
I think U should bind grid with null value within

page_Load(....)
if(!isPostback)
{
bindGrid();
}

try to...
 
Share this answer
 
Comments
karan joshua 8-Jun-11 10:51am    
thank u it works...
you may try this

<pre> protected void UpdateRecord(object sender, GridViewUpdateEventArgs e)
       {
           HJSoftware.BusinessAcceess.BusinessAccess ba = new HJSoftware.BusinessAcceess.BusinessAccess();
           int EmpID = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
           int intResult = 0;
           //string FileName = "";
           GridViewRow row = GridView1.Rows[e.RowIndex];
           DropDownList DdlGender = (DropDownList)row.FindControl("ddlGender");
           FileUpload ImageUpload = (FileUpload)row.FindControl("ImageUpload");
           FileUpload BiodataUpload = (FileUpload)row.FindControl("BiodataUpload");
           //TextBox DeptID = (TextBox)row.FindControl("txtDeptID");
           TextBox FirstName = (TextBox)row.FindControl("txtFirstName");
           TextBox LastName = (TextBox)row.FindControl("txtLastName");
           TextBox MiddleName = (TextBox)row.FindControl("txtMiddleName");
           TextBox Address1 = (TextBox)row.FindControl("txtAddress1");
           TextBox Address2 = (TextBox)row.FindControl("txtAddress2");
           TextBox State1 = (TextBox)row.FindControl("txtState1");
           TextBox ZipCode = (TextBox)row.FindControl("txtZipCode");
           //TextBox Gender = (TextBox)row.FindControl("txtGender");
           TextBox DOB = (TextBox)row.FindControl("txtDOB");
           TextBox Phone = (TextBox)row.FindControl("txtPhone");
           TextBox Email = (TextBox)row.FindControl("txtEmail");
           TextBox Designation = (TextBox)row.FindControl("txtDesignation");
           TextBox DateOfJoining = (TextBox)row.FindControl("txtDateOfJoining");
           TextBox DateOfReleving = (TextBox)row.FindControl("txtDateOfReleving");
           //FileTextBox BioData = (TextBox)row.FindControl("txtBioData");
          // TextBox Photo= (TextBox)row.FindControl("txtPhoto");
          // TextBox Status1 = (TextBox)row.FindControl("txtStatus1");
           Image image1 = (Image)row.FindControl("image");
           HyperLink hl1 = (HyperLink)row.FindControl("hl1");
           DropDownList DdlDept = (DropDownList)row.FindControl("DropDownList1");}

public int Update(int  EmpID,int DeptID,string FirstName,string LastName,string MiddleName,string Address1,
                     string Address2, string State1, int ZipCode, string Gender, int Phone,DateTime DOB, string Email, string Designation,DateTime DateOfJoining,DateTime DateOfReleving,string FileName,string BioData)
           {
            //this.connection();
            
            SqlCommand myCommand = new SqlCommand();
            SqlConnection myConnection = new SqlConnection(connectionString);
            myConnection.Open();
            myCommand = new SqlCommand("sp_UpdateEmployee", myConnection);
            myCommand.CommandType = CommandType.StoredProcedure;
            try
            {
                myCommand.Parameters.AddWithValue("@Photo", "images/" + FileName);
             myCommand.Parameters.AddWithValue("@EmpId",EmpID);
                myCommand.Parameters.AddWithValue("@DeptId",DeptID);
             myCommand.Parameters.AddWithValue("@FirstName",FirstName );
             myCommand.Parameters.AddWithValue("@LastName",LastName );
                 myCommand.Parameters.AddWithValue("@MiddleName",MiddleName );
             myCommand.Parameters.AddWithValue("@Address1",Address1 );
             myCommand.Parameters.AddWithValue("@Address2",Address2 );
             myCommand.Parameters.AddWithValue("@State1",State1 );
             myCommand.Parameters.AddWithValue("@ZipCode",ZipCode );
              myCommand.Parameters.AddWithValue("@Gender",Gender );
             myCommand.Parameters.AddWithValue("@DOB",DOB );
              myCommand.Parameters.AddWithValue("@Phone",Phone );
              myCommand.Parameters.AddWithValue("@Email",Email );
              myCommand.Parameters.AddWithValue("@Designation",Designation );
             myCommand.Parameters.AddWithValue("@DateOfJoining",DateOfJoining );
              myCommand.Parameters.AddWithValue("@DateOfReleving", DateOfReleving);
              myCommand.Parameters.AddWithValue("@BioData",BioData );
             // myCommand.Parameters.AddWithValue("@Photo",photo );
             //myCommand.Parameters.AddWithValue("@Status1",Status1);
             // myCommand.Parameters.AddWithValue("@MiddleName",MiddleName);*/

                return myCommand.ExecuteNonQuery();

            }

            catch
            {

                throw;

            }

            finally
            {

                myCommand.Dispose();

                myConnection.Close();

                myConnection.Dispose();

    }
 
Share this answer
 
v2

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