I have created some dynamic labels and some dynamic linkbuttons... those linkbuttons have addhandlers assigned to them... but in postback those buttons gets deleted...
the code is shown below... plz help asap...
Expand|Select|Wrap|Line Numbers
- Dim conn As New Data.OleDb.OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("connectionstring"))
- Dim itable As New Table
- Dim irow As New TableRow
- Dim icell(5), ic(5) As TableCell
- Dim txt As New Label
- Dim prd, sku As Label
- Dim tit As TextBox
- Dim skus As Label
- Dim upd, del As LinkButton
- Dim ic1(7), ic2(7) As TableCell
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- If Not Page.IsPostBack Then
- Dim ds As New Data.DataSet
- Dim select_cat As Data.OleDb.OleDbDataAdapter
- select_cat = New Data.OleDb.OleDbDataAdapter("select name from category order by pos", conn)
- select_cat.Fill(ds, "name")
- catitems.DataSource = ds.Tables(0).DefaultView
- catitems.DataBind()
- End If
- If Page.IsPostBack Then
- plc.Controls.Clear()
- Call headdel()
- Call get_deldata()
- End If
- End Sub
- Protected Sub catitems_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles catitems.SelectedIndexChanged
- txt.Text = catitems.SelectedValue
- Call headdel()
- End Sub
- Sub headdel()
- Dim edi, delet, zon, clas As Label
- Dim a As Integer
- For a = 0 To 5
- zon = New Label
- zon.Text = "Product title"
- clas = New Label
- clas.Text = "SKU"
- icell(a) = New TableCell
- edi = New Label
- edi.Text = "Update"
- delet = New Label
- delet.Text = "Delete"
- If a = 0 Then
- icell(a).Controls.Add(zon)
- End If
- If a = 1 Then
- icell(a).Controls.Add(clas)
- End If
- If a = 2 Then
- icell(a).Controls.Add(edi)
- End If
- If a = 3 Then
- icell(a).Controls.Add(delet)
- End If
- Next
- itable = New Table
- irow = New TableRow
- irow.BorderWidth = 1
- itable.BorderWidth = 1
- itable.Width = 650
- irow.BorderWidth = 1
- itable.Rows.Add(irow)
- irow.Cells.Add(icell(0))
- irow.Cells.Add(icell(1))
- irow.Cells.Add(icell(2))
- irow.Cells.Add(icell(3))
- 'plc.Controls.Add(itable)
- Call get_deldata()
- End Sub
- Sub get_deldata()
- Dim conn As New Data.OleDb.OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("connectionstring"))
- Dim comm As New Data.OleDb.OleDbCommand
- Dim reader As Data.OleDb.OleDbDataReader
- Dim state As String
- Dim b As Integer
- conn.Open()
- state = "select [title],sku from products where cat='" & txt.Text & "'"
- comm = New Data.OleDb.OleDbCommand(state, conn)
- reader = comm.ExecuteReader
- While reader.Read
- irow = New TableRow
- itable.Rows.Add(irow)
- prd = New Label
- sku = New Label
- ic1(0) = New TableCell
- prd.Text = reader.GetValue(0)
- ic1(0).Controls.Add(prd)
- ic1(1) = New TableCell
- sku.Text = reader.GetValue(1)
- ic1(1).Controls.Add(sku)
- itable.Rows.Add(irow)
- irow.Cells.Add(ic1(0))
- irow.Cells.Add(ic1(1))
- Dim conn1 As New Data.OleDb.OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("connectionstring"))
- Dim comm1 As New Data.OleDb.OleDbCommand
- Dim reader1 As Data.OleDb.OleDbDataReader
- Dim state1 As String
- conn1.Open()
- state1 = "select [sku],[prdtitle],[ID] from [prdfake] where [sku]='" & reader.GetValue(1) & "'"
- comm1 = New Data.OleDb.OleDbCommand(state1, conn1)
- reader1 = comm1.ExecuteReader
- While reader1.Read
- upd = New LinkButton
- upd.Text = "Update"
- 'AddHandler upd.Click, AddressOf updbtn
- 'upd.ID = "ty" & reader.GetValue(1)
- del = New LinkButton
- del.Text = "Delete"
- del.ID = "dt" & reader1.GetValue(0)
- AddHandler del.Click, AddressOf delbtn
- For b = 0 To 5
- tit = New TextBox
- tit.Text = reader1.GetValue(1)
- skus = New Label
- skus.Text = reader1.GetValue(0)
- ic2(b) = New TableCell
- If b = 0 Then
- ic2(b).Controls.Add(tit)
- ic2(b).Width = "100"
- End If
- If b = 1 Then
- ic2(b).Controls.Add(skus)
- ic2(b).Width = "100"
- End If
- If b = 2 Then
- ic2(b).Controls.Add(upd)
- ic2(b).Width = "50"
- End If
- If b = 3 Then
- ic2(b).Controls.Add(del)
- ic2(b).Width = "150"
- End If
- Next
- irow = New TableRow
- itable.Rows.Add(irow)
- irow.Cells.Add(ic2(0))
- irow.Cells.Add(ic2(1))
- irow.Cells.Add(ic2(2))
- irow.Cells.Add(ic2(3))
- End While
- conn1.Close()
- comm1.Dispose()
- conn1.Dispose()
- Dim add As LinkButton
- add = New LinkButton
- add.ID ="a" & reader.GetValue(1)
- add.Text = "Add new title"
- AddHandler add.Click, AddressOf show
- ic2(4) = New TableCell
- ic2(4).Controls.Add(add)
- ic2(4).Width = "100"
- irow.Cells.Add(ic2(4))
- End While
- conn.Close()
- comm.Dispose()
- conn.Dispose()
- plc.Controls.Add(itable)
- End Sub
- Public Sub show(ByVal sender As Object, ByVal e As EventArgs)
- Call headdel()
- Call get_deldata()
- End Sub
- Public Sub delbtn(ByVal sender As Object, ByVal e As EventArgs)
- Dim t As Integer = sender.ToString.Length
- Dim conn3 As New Data.OleDb.OleDbConnection(System.Configuration.ConfigurationManager.AppSettings("connectionstring"))
- Dim comm3 As New Data.OleDb.OleDbCommand
- Dim state3 As String
- Try
- Dim t1 As New Label
- t1.Text = "Product Title"
- state3 = "insert into [prdfake]([sku],[prdtitle]) values('" & t1.Text & "','" & t1.Text & "')"
- comm3 = New Data.OleDb.OleDbCommand(state3, conn3)
- conn3.Open()
- comm3.ExecuteNonQuery()
- Catch ex As Exception
- Response.Write(ex.Message)
- Finally
- If Not conn3 Is Nothing Then
- conn3.Close()
- End If
- conn3.Dispose()
- comm3.Dispose()
- Call headdel()
- End Try
- End Sub