Dear all,
Suppose we insert some data in a webpage with textboxes, after inserting the data One column data will be shown as a link in a gridview along with other data in second page, So when I click that link data another webpage will be shown with their all data in textboxes.In that page update and cancel button available to do the respective actions. I need to update some data.
How to do this ? Please help.
Thanks in Advance
Loading
Satyapriya NayakPosted Dec 27, 2011, 12:04 AM
Try this...
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Insert.aspx.vb" Inherits="Gridview_update_other_page_vb.Insert" %>
Imports System.Data
Imports System.Data.SqlClient
Partial Public Class Insert
Inherits System.Web.UI.Page
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New SqlConnection(strConnString)
Dim str As String
Dim com As SqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As DataSet
Protected Sub btn_insert_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btn_insert.Click
con.Open()
str = "insert into employee(Empname,EmpFname,EmpLname,Empcity,Empstate) values('" & txtFullName.Text & "','" & txtFName.Text & "','" & txtLName.Text & "','" & txtcity.Text & "','" & txtstate.Text & "')"
com = New SqlCommand(str, con)
com.ExecuteNonQuery()
con.Close()
Response.Redirect("Default.aspx")
End Sub
End Class
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="Gridview_update_other_page_vb._Default" %>
Imports System.Data
Imports System.Data.SqlClient
Partial Public Class _Default
Inherits System.Web.UI.Page
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New SqlConnection(strConnString)
Dim str As String
Dim com As SqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As DataSet
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
bind()
End If
End Sub
Sub bind()
con.Open()
str = "select * from employee"
com = New SqlCommand(str, con)
sqlda = New SqlDataAdapter(com)
con.Close()
ds = New DataSet()
sqlda.Fill(ds, "employee")
GridView1.DataSource = ds
GridView1.DataMember = "employee"
GridView1.DataBind()
End Sub
End Class
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Update.aspx.vb" Inherits="Gridview_update_other_page_vb.Update" %>
Imports System.Data
Imports System.Data.SqlClient
Partial Public Class Update
Inherits System.Web.UI.Page
Dim strConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings.Item("ConnectionString").ToString()
Dim con As New SqlConnection(strConnString)
Dim str As String
Dim com As SqlCommand
Dim sqlda As SqlDataAdapter
Dim ds As DataSet
Dim empid As Integer = 0
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
empid = Convert.ToInt32(Request.QueryString("Empid").ToString())
If Not IsPostBack Then
bind()
End If
End Sub
Sub bind()
con.Open()
str = "select * from employee where Empid=" & empid
com = New SqlCommand(str, con)
sqlda = New SqlDataAdapter(com)
com.ExecuteNonQuery()
con.Close()
ds = New DataSet()
sqlda.Fill(ds)
lblFullName.Text = ds.Tables(0).Rows(0)(1).ToString()
txtFName.Text = ds.Tables(0).Rows(0)(2).ToString()
txtLName.Text = ds.Tables(0).Rows(0)(3).ToString()
txtcity.Text = ds.Tables(0).Rows(0)(4).ToString()
txtstate.Text = ds.Tables(0).Rows(0)(5).ToString()
End Sub
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnUpdate.Click
con.Open()
str = "update employee set EmpFname='" & txtFName.Text & "',EmpLname='" & txtLName.Text & "',Empcity='" & txtcity.Text & "',Empstate='" & txtstate.Text & "' where Empid=" & empid
com = New SqlCommand(str, con)
sqlda = New SqlDataAdapter(com)
Dim result As Integer
result = com.ExecuteNonQuery()
con.Close()
If result = 1 Then
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "ShowSuccess", "javascript:Display('" & lblFullName.Text & "')", True)
End If
End Sub
Protected Sub btnCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnCancel.Click
Response.Redirect("~/Default.aspx")
End Sub
End Class
Thanks
If this post helps you mark it as answer
kundan mohantaPosted Dec 27, 2011, 12:30 AM