Farily simple question, I think, but am stuck and would appreciate some help. The goal of the page is this: a dropdown box, from which 1 to 30 can be selected, and from the number selected a corresponding number of textboxes generated. The user will enter data in each text box, the data averaged and the average displayed.
The code is below. There are two main areas in which I'm not sure how to proceed.
1) In the BuildDataEntryForm subroutine (triggered by the onSelectedIndexChanged event of the dropdownlist), I attempt to build out a series of textboxes. However, the code below produces the following result (or something similar):
System.Web.UI.WebControls.TextBoxEnter Value System.Web.UI.WebControls.TextBoxEnter Value System.Web.UI.WebControls.TextBoxEnter Value ... ... ...
That is, it displays the reference names of the textboxes, but does not actually place a textbox in the form.
2) In the Calculate routine, I simply want to retrieve the values from each of the textboxes, convert them to numeric form, and calculate an average. However, given the above there are no textboxes from which the values can be extracted.
I hope that explains the issue sufficiently. Any help will be appreciated.
The code is copied below:
<Script Language="
VB" Runat="Server" >
Sub Page_Load()
If Not Page.IsPostback Then
txtLabel1.Visible = False
btnCalculate.Visible = False
Dim ListIndex = New ArrayList
Dim intX as Integer
For intX = 1 to 30
ListIndex.Add(intX)
Next intX
ListIndex.TrimToSize()
lstDropDown.DataSource=ListIndex
lstDropDown.DataBind()
End If
lstDropDown.AutoPostBack = True
End Sub
Sub BuildDataEntryForm(Source As Object, e as EventArgs)
txtLabel1.Visible = False
btnCalculate.Visible = True
Dim intX As Integer
Dim arrList = New ArrayList
For intX = 1 to lstDropDown.SelectedItem.Value
arrList.add(new TextBox())
Next intX
rptRepeater.DataSource=arrList
rptRepeater.DataBind()
End Sub
Sub Calculate(Source As Object, e As EventArgs)
Dim strTemp as String = ""
Dim txtTemp as New TextBox()
txtLabel1.Visible = True
For Each item As RepeaterItem In rptRepeater.Items
'**** Not Sure What Should Go Here
Next item
Response.Write(txtTemp)
End Sub
</script>
<html>
<body>
<h3>Enter the numbers to be averaged</h3>
<form Runat="Server">
<asp:dropdownlist id="lstDropDown" Runat="Server" onSelectedIndexChanged="BuildDataEntryForm" /> <br />
<asp:Repeater id="rptRepeater" Runat="Server">
<ItemTemplate>
<%#Container.DataItem%>Enter Value
</ItemTemplate>
</asp:Repeater>
<asp:Button id="btnCalculate" Runat="Server" OnClick="Calculate" Text="Calculate Average" />
<br />
<asp:textbox id="txtLabel1" Runat="Server" />
</form>
</body>
</html>