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

编程入门 行业动态 更新时间:2024-10-18 16:43:39
本文介绍了获取gridview的更新值时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用C#,asp,服务器2005和Visual Studio 2005 我的Gridview包含一行5列. 当页面加载发生时,我正在用空值填充gridview.. 现在我更改gridview中的值(文本框的值)... 现在的问题是,当我单击保存"按钮时,将发生页面加载时的值保存到数据库中……即,空值. 但我想保存文本框的更新值 如何在不使用任何事件的情况下获取每一列的值... 请帮我.. 问候 karan

I''m using C#,asp,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

推荐答案

问题很简单.如您所说,您正在用页面加载时的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(); }

更多推荐

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

本文发布于:2023-11-23 20:39:08,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622798.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:gridview

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!