Add Two Controls in a Table Cell not working - asp.net

Hi I am trying to add two controls into a table cell the code is below. Unfortunately the hyperlink is always outside the table cell, whilst the label is inside. Individually they are working fine but together not so good, could somebody help me please.
Dim iCell As New TableCell
Dim lbl As New Label
lbl.Height = Unit.Pixel(100)
lbl.Width = Unit.Pixel(150)
lbl.Style.Add("padding", "5px")
lbl.Style.Add("border-radius", "10px")
lbl.BorderStyle = BorderStyle.Solid
lbl.BorderWidth = Unit.Pixel(1)
lbl.BorderColor = Color.Black
lbl.Font.Size = 9
lbl.Text = "Event: " & dt.Rows(y).Item("eventname")
lbl.BackColor = ColorTranslator.FromHtml(dt.Rows(y).Item("roomcolor"))
Dim hyp As New HyperLink
hyp.Font.Size = 9
hyp.Text = "Modify"
hyp.NavigateUrl = "modify.aspx"
iCell.Controls.Add(lbl)
iCell.Controls.Add(hyp)
iCell.VerticalAlign = VerticalAlign.Top
tRow.Cells.Add(iCell)

Related

get values of dynamic checkboxes

I am dynamically creating checkboxes in VB.Net and an .aspx page, based on values in my db. I'm placing them in a two column table for ease of alignment. this part works fine.
Private Async Function InitForEditAsync() As Task
Dim docList = Await GetLoanApplicationConfigurationDocs()
Dim row = New HtmlTableRow()
Dim cell = New HtmlTableCell()
Dim i = 0
For Each doc In docList
Dim chkBox = New HtmlInputCheckBox()
Dim lbl = New Label()
Dim remainder = i Mod 2
chkBox.ID = "chkDocId" + doc.Id.ToString
lbl.Text = doc.DisplayName
cell.Controls.Add(chkBox)
cell.Controls.Add(lbl)
row.Cells.Add(cell)
cell = New HtmlTableCell()
If remainder <> 0 OrElse i = docList.Count() - 1 Then
tblEdit.Rows.Add(row)
row = New HtmlTableRow()
End If
i += 1
Next
End Function
Now I need to retrieve the values without knowing the id's but am not having any luck. I tried this:
For Each chkBox As HtmlInputCheckBox In pnlEdit.Controls.OfType(Of HtmlInputCheckBox)
but the checkboxes are not returned in the list of controls. The table is, but there are no rows in the table object when I explored it in the control collection and when I tried this:
For Each row As HtmlTableRow In tblEdit.Rows.OfType(Of HtmlTableRow)
If it will help, here is a Snip of the UI and the HTML that is created:
Any suggestions are appreciated. Thanks in advance.
Based on some ideas I got from another site, I'm going to rewrite this using the asp:CheckBoxList. apparently it binds like a datagrid and you can enumerate through it. Seems like what i need.
UPDATE: Everything I posted to start was resolved with five lines of code! "cblDocList is my asp CheckboxList and docList is my ienumerable of objects.
cblDocList.RepeatColumns = 2
cblDocList.DataSource = docList
cblDocList.DataTextField = "DisplayName"
cblDocList.DataValueField = "Id"
cblDocList.DataBind()
It’s something you can do through a loop for each row and each cell or using Linq to have only cells that have controls of type HtmlInputCheckBox inside.
I have simplified your code to be able run that here also shows you an example to achieve your task. Obviously you must change following your exigences .
Hope I well understood :)
Dim tblEdit As New HtmlTable
For k As Integer = 0 To 10
Dim cell = New HtmlTableCell()
Dim row = New HtmlTableRow()
Dim chkBox = New HtmlInputCheckBox()
Dim lbl = New Label()
Dim remainder = k Mod 2
chkBox.ID = "chkDocId_" + k.ToString
chkBox.Checked = remainder = 0
lbl.Text = "Text indicator of CheckBox nr:" + k.ToString
cell.Controls.Add(chkBox)
cell.Controls.Add(lbl)
row.Cells.Add(cell)
cell = New HtmlTableCell()
tblEdit.Rows.Add(row)
Next
Dim checkBoxes As IEnumerable(Of HtmlInputCheckBox) =
(From mRow In tblEdit.Rows).Select(Function(mr)
Dim cb = (From cc In CType(mr, HtmlTableRow).Cells
Where CType(cc, HtmlTableCell).Controls.OfType(Of HtmlInputCheckBox).Count > 0
Select CType(cc, HtmlTableCell).Controls.OfType(Of HtmlInputCheckBox)()(0)).FirstOrDefault
Return CType(cb, HtmlInputCheckBox)
End Function).ToList
For Each checkBox In checkBoxes
Debug.WriteLine("CheckBox ID: {0} Checked: {1} ", checkBox.ID, checkBox.Checked)
Next

adding a chart control to a placeholder ASP.net VB

I'm trying to add a manually created chart to a placeholder but when i look at the output all i get is a blank.. I am getting the data from a dataset datatable that is the last table in the dataset. I only has two colums "Industry" and "industryTheta" any help is much appreciated. I'm not sure whats wrong here
Dim chrt As New Chart
chrt.ID = "dynChart"
chrt.Height = Unit.Pixel(1000)
chrt.Width = Unit.Pixel(1000)
chrt.BackImageWrapMode = ChartImageWrapMode.Scaled
chrt.BorderlineColor = Color.Black
chrt.ImageLocation = "~/TempImages/ChartPic_#SEQ(300,3)"
chrt.BackGradientStyle = GradientStyle.None
Dim ca As New ChartArea
ca.Name = "IndustryTheta"
ca.AlignmentOrientation = AreaAlignmentOrientations.All
ca.AlignmentStyle = AreaAlignmentStyles.All
ca.Area3DStyle.Enable3D = True
ca.Area3DStyle.LightStyle = LightStyle.Realistic
ca.Area3DStyle.Inclination = 30
ca.BackHatchStyle = ChartHatchStyle.None
chrt.ChartAreas.Add(ca)
Dim sers As New Series
sers.Name = "IndustryName"
sers.ChartType = SeriesChartType.Pie
sers.Label = "#VALX, #PERCENT"
sers.LabelAngle = 90
sers.IsXValueIndexed = True
sers.IsValueShownAsLabel = True
sers.XAxisType = AxisType.Primary
sers.YAxisType = AxisType.Primary
sers.YValuesPerPoint = 1
sers.XValueMember = "Industry"
sers.YValueMembers = "IndustryTheta"
chrt.Series.Add(sers)
For Each dr As DataRow In table.Rows
Dim p As New DataPoint
p.SetValueY(Convert.ToInt32(dr.Item("IndustryTheta")))
p.AxisLabel = dr.Item("Industry")
sers.Points.Add(p)
Next
chrt.DataBind()
dynamicGrids.Controls.Add(chrt)
Most likely your problem is with when you are calling your function in the page life cycle. Please refer to this information to learn more about it.
In order to address dynamic controls in asp.net please refer to this for more information on dynamic controls.

Creating a label inside Gridview Cell from VB

I have some Code in VB that is looping through a gridview's rows and is checking the values of a certain collumn, I have written some code inside the if statement that creates a clickable label inside the cell for when the cell is "", I have already written a bit of code that could create my label but I'm not too sure how it would create it inside row.Cells(8)
I was wondering if could get some assistance with how I should be doing this?...
Here's my Code:
For i As Integer = 0 To GridView1.Rows.Count - 1
Dim row = GridView1.Rows(i)
Dim rowHeaderCell = row.Cells(8)
If rowHeaderCell.Text = " " Then
Dim lbl As New Label
lbl.Size = New System.Drawing.Size(159, 23)
lbl.Location =
lbl.Text = "label text goes here"
Me.Controls.Add(lbl)
End If
Next
Thankyou in advance!
To make a clickable label change the type of the column to : [DataGridViewLinkColumn]
here is the code to replace the Empty cell value by the value of LBL:
For i As Integer = 0 To GridView1.Rows.Count - 1
If GridView1.Rows(i).Cells(8).Value.Trim = "" Then
Dim lbl As String
lbl = "label text goes here "
GridView1.Rows(i).Cells(8).Value = lbl
End If
Next

how to get values from dynamically created textboxes?

I dynamically create textboxes by a click of a button... then i would like to get the values from the textboxes that i created to insert to the database.. I use VB.NET 2008.
this are some sample codes..
For x As Integer = 0 To mydt.Rows.Count - 1
l = New Label()
tb = New TextBox()
tb.ID = x.ToString()
l.ID = x.ToString
l.Text = bb
Panel1.Controls.Add(l)
Panel1.Controls.Add(tb)
tb.Text = mydt.Rows(x).Item(0)
Next
I just assumed that you are working in winforms, You can do it by assigning unique name to your text boxes like this,
For x As Integer = 0 To mydt.Rows.Count - 1
l = New Label()
tb = New TextBox()
tb.name = "txt" & x 'Name your text box
tb.ID = x.ToString()
l.ID = x.ToString
l.Text = bb
Panel1.Controls.Add(l)
Panel1.Controls.Add(tb)
tb.Text = mydt.Rows(x).Item(0)
Next
So in the next step, since you are adding those textboxes in to panel1, you can fetch it directly from that container like below,
For x As Integer = 0 To mydt.Rows.Count - 1
MsgBox(Ctype( panel1.Controls("txt" & x),textbox).text)
Next

how to identify Label control in for each Silverlight Datagrid

how to identify label control in foreach Silverlight Datagrid
For Each item In TaskDataGrid.ItemsSource
TryCast(TryCast(item, StackPanel).Children(2), Label).Content = "New Text"
Next
I have label control in 2 nd Column how to identify and assign the value
This is working fine..
For Each rowItem In TaskDataGrid.ItemsSource
' Ensures that all rows are loaded.
TaskDataGrid.ScrollIntoView(rowItem, TaskDataGrid.Columns.Last())
Dim fe As FrameworkElement = TaskDataGrid.Columns(2).GetCellContent(rowItem)
Dim fe1 As FrameworkElement = TaskDataGrid.Columns(1).GetCellContent(rowItem)
Dim gridCmbo As Grid = DirectCast(fe, Grid)
Dim gridCmbo1 As Grid = DirectCast(fe1, Grid)
Dim lbltaskId As Label = CType(gridCmbo1.FindName("lbltaskId"), Label)
Dim lblBaseReceipt As Label = CType(gridCmbo.FindName("lblBaseReceipt"), Label)
Next

Resources