i have created a dyanmic table and attached with gridview .now i want to edit the data in gv.how can we do it.i have tried but it is not working.Pls help

Can you post the code you have so far? There are a few ways to do this and we'll be able to help better if we can see what direction you're headed.

in rowupdating method ...just give this coding...

gridview.editindex=e.neweditindex;
binddatat();

here concentrate the case ......
in binddata() method just bind the gridview coding.

Imports System.Data
Imports System.Data.SqlClient
Partial Class MyCart
    Inherits System.Web.UI.Page
    Dim DT As System.Data.DataTable
    Dim DR As DataRow
    Dim Match As Boolean = False
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            If Not Session("Cart") Is Nothing Then
                DT = Session("Cart")
                GridView1.DataSource = DT
                GridView1.DataBind()
                lbltotal.Text = TotalAmount(DT)
                lbltotalitem.Text = DT.Rows.Count & " Items"
                lbltotalitemprice.Text = TotalAmount(DT)
                dv.Visible = True
            Else
                dv.Visible = False
            End If
        End If
    End Sub
    Function TotalAmount(ByVal DT As DataTable) As Decimal
        Dim returntotal As Decimal
        For Each DR In DT.Rows
            returntotal += DR("saleprice") * DR("Qty")
        Next
        Return returntotal
    End Function
    Protected Sub GridView1_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles GridView1.RowDeleting
        DT = Session("Cart")
        DT.Rows(e.RowIndex).Delete()
        Session("Cart") = DT
        GridView1.DataSource = DT
        GridView1.DataBind()
        lbltotal.Text = TotalAmount(DT)
    End Sub
    
End Class

-------------------------------------------------------------------------

Imports System.Data
Imports System.Data.SqlClient
Partial Class ProductInformation
    Inherits System.Web.UI.Page
    Dim DT As DataTable
    Dim DR As DataRow
    Dim Match As Boolean = False
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim Con As New SqlConnection
            Con.ConnectionString = "Data source=SOFT-D5F98EFF93;Initial Catalog=ECommerce;Integrated Security=True"
            Dim Com As New SqlCommand("Select * from Products Where ProductID='" + Request.QueryString("ID") + "'", Con)
            Dim DR As SqlDataReader
            Con.Open()
            DR = Com.ExecuteReader
            If DR.HasRows Then
                While DR.Read
                    img1.ImageUrl = DR("Product Path")
                    lblid.Text = DR("ProductID")
                    lblisactive.Text = DR("IsActive")
                    lblsaleprice.Text = DR("SalePrice")
                End While
            End If
            Con.Close()
            If Session("Cart") Is Nothing Then
                MakeCart()
            End If

        End If
    End Sub
    Protected Sub btnAdd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        AddToCart()
        Dim str As String
        str = "<script language='javascript'>window.close();</script>"
        Response.Redirect("Close.aspx")
    End Sub
    Sub MakeCart()
        DT = New DataTable("MyCart")
        DT.Columns.Add("ID", GetType(Integer))
        DT.Columns.Add("SalePrice", GetType(Decimal))
        DT.Columns.Add("Qty", GetType(Integer))
        DT.Columns.Add("Total", GetType(Decimal))
        Session("Cart") = DT
    End Sub
    Sub AddToCart()
        DT = Session("Cart")
        MatchProduct(DT)
        If Not Match Then
            DR = DT.NewRow
            DR("ID") = lblid.Text
            DR("SalePrice") = Decimal.Parse(lblsaleprice.Text)
            DR("Qty") = txtqty1.Text
            DR("Total") = (Decimal.Parse(lblsaleprice.Text) * CType(txtqty1.Text, Integer))
            DT.Rows.Add(DR)
            Session("Cart") = DT
        End If

    End Sub
    Function TotalAmount(ByVal DT As DataTable) As Decimal
        Dim RV As Decimal
        For Each DR In DT.Rows
            RV += DR("Qty") * DR("Saleprice")
        Next
        Return RV
    End Function
    Sub MatchProduct(ByVal DT As DataTable)
        For Each DR In DT.Rows
            If DR("ID") = lblid.Text Then
                DR("Qty") = txtqty1.Text
                Match = True
                Exit For
            End If
        Next
    End Sub
End Class
This article has been dead for over six months. Start a new discussion instead.