First You Make one item Template To Show Data and One Edit Item Template enable editing in grid view like this
< asp: TemplateField HeaderText="Sub Department"
This line will Show Textbox at the place of label
GridViewPP.EditIndex = e.NewEditIndex
complete code :
Protected Sub GridViewPP_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridViewPP.RowEditing
GridViewPP.EditIndex = e.NewEditIndex
QRY = "SELECT SubDepartment.SubDepartment_ID,SubDepartment.Department_ID, Department.DepartmentDescription,SubDepartment.SubDepartment_Description, Employee.UserName AS CreatedBy,Employee_1.UserName AS ModifyBy, SubDepartment.CreatedOn,SubDepartment.ModifyOn FROM Department RIGHT OUTER JOIN Employee RIGHT OUTER JOIN SubDepartment LEFT OUTER JOIN Employee AS Employee_1 ON SubDepartment.ModifyBy = Employee_1.UserID ON Employee.UserID = SubDepartment.CreatedBy ON Department.DepartmentID = SubDepartment.Department_ID"
This Query show all data in gridview and textbox as there you want to update data
end sub
Now on Update Button in GridView
Protected Sub GridViewPP_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridViewPP.RowUpdating
Dim row As GridViewRow = CType(GridViewPP.Rows(e.RowIndex), GridViewRow)
Dim subDept As Label = CType(row.FindControl("lblsubDeptID"), Label)
Dim subDeptDesc As TextBox = CType(row.FindControl("txtSubDeptDesc"), TextBox)
pass Subdept and subDeptDesc in the update Query Like this
QRY = "Update SubDepartment Set SubDepartment_Description='" & subDeptDesc.Text & "',ModifyOn='" & datetime & "',ModifyBy='" & Session("UserID") & "' where SubDepartment_ID=" & subDept.Text
You can update data at runtime in grid view .
No comments:
Post a Comment