且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

获取gridview的更新值时出现问题

更新时间:2022-12-28 19:59:14

问题很简单.如您所说,您正在用页面加载时的NULL值填充gridview,因此,当您单击保存按钮时,将再次调用页面加载,并且它将用NULL重新填充gridview.您将必须检查页面加载,以查看gridview是否已具有值,它不应使用NULL之类的值将其填充回去.

希望对您有所帮助.
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.


我认为您应该在
中将网格绑定为空值
page_Load(....)
if(!isPostback)
{
bindGrid();
}

尝试...
I think U should bind grid with null value within

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

try to...


您可以尝试此

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();

    }