can I add my drop down list twice in different cells? Now it works only for the last cell, so I have one drop down list in las cell. Must I create each time new drop down list or how can I make it?
Thanks in advance
Dim ddltest As New DropDownList
ddltest.ID = "ddltest"
ddltest.Width = Unit.Pixel(270)
ddltest.Enabled = False
ddltest.Items.Add(New ListItem("text1", "value1"))
ddltest.Items.Add(New ListItem("text2", "value2"))
ddltest.SelectedItem.Text = ddltest.Items.FindByValue("value2").Text
row01.Cells.Add(New TableCell)
row01.Cells(1).Width = Unit.Pixel(300)
row01.Cells(1).Controls.Add(ddltest)
ddltest.SelectedItem.Text = ddltest.Items.FindByValue("value1").Text
row01.Cells.Add(New TableCell)
row01.Cells(2).Width = Unit.Pixel(300)
row01.Cells(2).Controls.Add(ddltest)
Create you DDL in a function and then add it with different IDs to your cells
Private Function DDLCreate(ByVal Id As String) As DropDownList
Dim ddltest As New DropDownList
ddltest.ID = Id
ddltest.Width = Unit.Pixel(270)
ddltest.Enabled = False
ddltest.Items.Add(New ListItem("text1", "value1"))
ddltest.Items.Add(New ListItem("text2", "value2"))
Return ddltest
End Function
and then you can use it as often as you want like
row01.Cells(2).Controls.Add(DDLCreate("DDL1"))
row01.Cells(3).Controls.Add(DDLCreate("DDL2"))
Cheers Alex
Related
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
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.
I am binding a datatable to an asp.net chart but want to set the value of the label to a different dataitem (called ResLabelText) than used for the x or y axis. Can this be done? My databinding code is as follows:
chartRes.Series("Month").XValueMember = "MonthName"
chartRes.Series("Month").YValueMembers = "Res"
chartRes.Series("Month").Label = "ResLabelText"
chartRes.Series("Month").ToolTip = "#VALX"
chartRes.DataSource = dt
chartRes.DataBind()
Correct way:
For Each row In dt.Rows
Dim point = New DataPoint()
point.SetValueXY(row.Item("MonthName"), row.Item("Res"))
point.Label = row.Item("LabelRes")
point.ToolTip = row.Item("MonthName")
chartRes.Series("Month").Points.Add(point)
Next
I am trying programatically add a check box column to a grid view. This grid view has multiple other columns but I only want the check box column to be editable. The only examples I have seen require that I add an "Edit" link to each row. I would like for the check box column to be editable by default, without the need for a link. The check box should also support autopost backs. Anyone have any suggestions? Below is what I have so far:
Dim gv As New GridView
With gv
.ID = "gridViewFoundUsers"
.AutoGenerateColumns = False
.DataKeyNames = New String() {"UserId"}
.GridLines = GridLines.Both
.AllowSorting = True
.AllowPaging = True
.PageSize = numRows
.Width = tableWidth
.BorderColor = Drawing.ColorTranslator.FromHtml("#808080")
.AutoGenerateEditButton = True
.HeaderStyle.CssClass = foundUserHeadStyle
.RowStyle.CssClass = foundUserEvenRows
.Columns.Clear()
Dim UserIdTF As New BoundField
With UserIdTF
.DataField = "UserId"
.HeaderText = "UserID"
.SortExpression = "UserId"
.ItemStyle.Wrap = True
.ItemStyle.Width = 100
End With
Dim DomainTF As New BoundField
With DomainTF
.HeaderText = "Domain"
.DataField = "Domain"
.SortExpression = "Domain"
.ItemStyle.Wrap = False
.HeaderStyle.Font.Underline = False
End With
Dim SelectUserTF As New CheckBoxField
With SelectUserTF
.HeaderText = "Select User"
.ItemStyle.Wrap = False
.DataField = "isSelected"
End With
.Columns.Add(UserIdTF)
.Columns.Add(DomainTF)
.Columns.Add(SelectUserTF)
End With
The gridview is part of a composite server control, so there is no client side code pages.
Thanks!
I have the following code:
Dim i As Integer
For i = 1 To 20
Dim captionTextBox As TextBox = DirectCast(Me.FindControl("news_Image" + i.ToString() + "CaptionTextBox"), TextBox)
Dim deleteCheckBox As CheckBox = DirectCast(Me.FindControl("Image" + i.ToString() + "DeleteCheckBox"), CheckBox)
If Not deleteCheckBox.Checked = False Then
If Not captionTextBox.Text = "" Then
'Insert the value of the textbox into the column like news_Image1Caption, news_image2Caption nased on the value of i
End If
End If
Next
Where the comment is in the code above, I need to insert the value of the textbox (text) into Linq columns. For example: articleToUpdate.news_Image1Caption, news_Image2Caption, but I need to change the number after news_ to the value of i in the for loop. How can I do this?
Thanks
Luke
Did you try to set the ID column to Auto-Generated Value = true ?
INSERT INTO [dbo].[s_Tbl]([ID], [news_Image1Caption], [news_image2Caption]) VALUES (...)