Linkbutton control problem
-
hi all , iam not able to add linkbutton control to table cell can any body suggest me where iam doing wrong i have used following code to add linkbutton control to table cells
Dim myarray() As Integer = {0, 1, 2, 1, 4, 5, 6, 7, 1, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
Dim d As Integer
For d = 0 To 31
Dim tc As TableCell = New TableCell
If myarray(d) = 1 Then
Dim linkbutton As LinkButton = New LinkButton()
linkbutton.ID = "lnkbutton"
linkbutton.Text = " click here"
tc.Controls.Add(linkbutton)
'tc.BackColor = Color.DarkGreen
Else
tc.BackColor = Color.Yellow
End If
tc.Text = " "
trow.Cells.Add(tc)
NextTable.Rows.Add(trow)
or alternate way how i do that. Best regards Rameez
-
hi all , iam not able to add linkbutton control to table cell can any body suggest me where iam doing wrong i have used following code to add linkbutton control to table cells
Dim myarray() As Integer = {0, 1, 2, 1, 4, 5, 6, 7, 1, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
Dim d As Integer
For d = 0 To 31
Dim tc As TableCell = New TableCell
If myarray(d) = 1 Then
Dim linkbutton As LinkButton = New LinkButton()
linkbutton.ID = "lnkbutton"
linkbutton.Text = " click here"
tc.Controls.Add(linkbutton)
'tc.BackColor = Color.DarkGreen
Else
tc.BackColor = Color.Yellow
End If
tc.Text = " "
trow.Cells.Add(tc)
NextTable.Rows.Add(trow)
or alternate way how i do that. Best regards Rameez
-
You are doing it the right way. What error are you getting.
Ahsan Ullah Senior Software Engineer
Thanks Ahsanullah for reply. linkbutton control is not added to table cell i mean nothing to added into cell. i have to add linkbuton control to table cells dynamically. please suggest me where iam doing mistake . best regards Rameez
-
hi all , iam not able to add linkbutton control to table cell can any body suggest me where iam doing wrong i have used following code to add linkbutton control to table cells
Dim myarray() As Integer = {0, 1, 2, 1, 4, 5, 6, 7, 1, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
Dim d As Integer
For d = 0 To 31
Dim tc As TableCell = New TableCell
If myarray(d) = 1 Then
Dim linkbutton As LinkButton = New LinkButton()
linkbutton.ID = "lnkbutton"
linkbutton.Text = " click here"
tc.Controls.Add(linkbutton)
'tc.BackColor = Color.DarkGreen
Else
tc.BackColor = Color.Yellow
End If
tc.Text = " "
trow.Cells.Add(tc)
NextTable.Rows.Add(trow)
or alternate way how i do that. Best regards Rameez
hopefully you have created tablerow before loop. otherwise code is perfect.
-
hopefully you have created tablerow before loop. otherwise code is perfect.
Here is my complete code
Dim myarray() As Integer = {0, 1, 2, 1, 4, 5, 6, 7, 1, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31}
Dim d As Integer
Dim trow As TableRow = New TableRow()
For d = 0 To 31
Dim tc As TableCell = New TableCell
If myarray(d) = 1 Then
Dim lnkbutton As LinkButton = New LinkButton()
lnkbutton.ID = "lnkbutton"
lnkbutton.Text = "Click Here dear "
lnkbutton.PostBackUrl = ""
AddHandler lnkbutton.Click, AddressOf OnClickLink
tc.Controls.Add(lnkbutton)
Else
tc.BackColor = Color.Yellow
End If
tc.Text = " "
trow.Cells.Add(tc)Next Table1.Rows.Add(trow)
and here is event handler for that.
Protected Sub OnClickLink(ByVal sender As Object, ByVal e As EventArgs)
FormView1.Visible = True
Dim myConnection As New SqlConnection("Server=localhost;Database=xyz;uid=sa;pwd=xxxx")
Dim ad As New SqlDataAdapter("SELECT * FROM name of table", myConnection)
Dim ds As New DataSet()
ad.Fill(ds)
FormView1.DataSource = ds
FormView1.DataBind()End Sub
in above code nothing is added to table cell can any body suggest me where iam doing wrong . Best Regards Rameez