Delete a raw from a table by dynamically created button RRS feed

  • Question

  • Hello,

    I've been new to vb asp.net web development and I'm looking for a solution for this issue since a week. but still, the situation is same.

    what I want to do is, I need to delete the selected row which has been created dynamically in the web page. I have been trying several methods. but none of these are working. 

    this is my codes and sample screen. 

    Imports System.Data
    Partial Class add_stock
        Inherits System.Web.UI.Page
        Private numOfColumns As Integer = 1
        Private ctr As Integer = 0
        Private table As Table = Nothing
        Dim row As New TableRow()
        Dim cell As New TableCell()
        Dim tb9 As New Button
        Dim panel2 As New Panel
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
            If Not IsPostBack Then
                table = New Table()
                table.ID = "tableBuild"
                Session("table") = table
                ViewState("ctr") = ctr
            End If
            ctr = CType(ViewState("ctr"), Int32)
            table = DirectCast(Session("table"), Table)
        End Sub
        Private Sub GenerateTable(ByVal colsCount As Integer)
            ctr += 1
            Dim tb As New TextBox()
            tb.Text = TextBox21.Text
            tb.ID = "TextBoxRow_" & ctr
            tb.Width = 80
            tb.Enabled = False
            Dim cell1 As New TableCell()
            Dim tb1 As New TextBox()
            tb1.Text = TextBox19.Text
            tb1.ID = "TextBox1Row_" & ctr
            tb1.Width = 80
            tb1.Enabled = False
            Dim cell2 As New TableCell()
            Dim tb2 As New TextBox()
            tb2.Text = TextBox22.Text
            tb2.ID = "TextBox2Row_" & ctr
            tb2.Width = 80
            tb2.Enabled = False
            Dim cell3 As New TableCell()
            Dim tb3 As New TextBox()
            tb3.Text = TextBox17.Text
            tb3.ID = "TextBox3Row_" & ctr
            tb3.Width = 80
            tb3.Enabled = False
            Dim cell4 As New TableCell()
            Dim tb4 As New TextBox()
            tb4.Text = TextBox23.Text
            tb4.ID = "TextBox4Row_" & ctr
            tb4.Width = 80
            tb4.Enabled = False
            Dim cell5 As New TableCell()
            Dim tb5 As New TextBox()
            tb5.Text = TextBox20.Text
            tb5.ID = "TextBox5Row_" & ctr
            tb5.Width = 80
            tb5.Enabled = False
            Dim cell6 As New TableCell()
            Dim tb6 As New TextBox()
            tb6.Text = TextBox18.Text
            tb6.ID = "TextBox6Row_" & ctr
            tb6.Width = 80
            tb6.Enabled = False
            Dim cell7 As New TableCell()
            Dim tb7 As New TextBox()
            tb7.Text = DropDownList4.Text
            tb7.ID = "TextBox7Row_" & ctr
            tb7.Width = 80
            tb7.Enabled = False
            Dim cell8 As New TableCell()
            Dim tb8 As New TextBox()
            tb8.Text = DropDownList3.Text
            tb8.ID = "TextBox8Row_" & ctr
            tb8.Width = 80
            tb8.Enabled = False
            Dim cell9 As New TableCell()
            tb9.Text = "Delete"
            tb9.ID = ctr
            tb9.Width = 80
            'tb9.Enabled = False
            AddHandler tb9.Click, AddressOf Me.Button3_Click
            'tb9 = New CheckBox()
            'tb9.ID = "chkExample"
            'tb9.Text = "Check / Uncheck"
            'tb9.AutoPostBack = True
            'AddHandler tb9.CheckedChanged, AddressOf Button3_Click
            Session("table") = table
            ViewState("ctr") = ctr
        End Sub
        Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            '   ClientScript.RegisterStartupScript(Me.GetType, "Button_Alert", "alert('Button clicked!');", True)
            numOfColumns = 1
            'Generate the Table based from the inputs
        End Sub
        Protected Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs)
            ClientScript.RegisterStartupScript(Me.GetType, "Button_Alert", "alert('Button clicked!');", True)
            numOfColumns = 1
            'Generate the Table based from the inputs
        End Sub
        Protected Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        End Sub
    End Class

    Friday, April 20, 2018 8:58 AM

All replies

  • Most will point you to the ASP.Net forums, but I've seen an other contributor complaining that there are no answers given and certainly not on this kind of questions. While this is a real VB problem likewise the so often handled winform questions in this forum.

    It has to do that a Webform has no state like a winform. It means that you have to get the flushed data again back into your table before you use it at postback. 

    Luckily you did put it in the session, so I guess the only thing you've to do is in the button events

    Maybe better that you start using 2018 conventions and start global values with an upper case, in this case Table. 


    Friday, April 20, 2018 9:13 AM