我对这个主题有几个问题,仍然有问题。
我想从转发器控件内的许多下拉列表和文本框控件中查找值。
db.ConnectionString = SystemConnString
db.Open()
Dim selectedAdTitle As String = ""
Dim enteredAdFullName As String = ""
cmd.Parameters.Add(New SqlParameter("@TransactionID", TransactionID))
cmd.Parameters.Add(New SqlParameter("@AdTitle", selectedAdTitle))
cmd.Parameters.Add(New SqlParameter("@AdFullName", enteredAdFullName))
For i As Integer = 0 To myRepeater.Items.Count - 1
Dim AdTitle As DropDownList = DirectCast(myRepeater.Items(i).FindControl("AdTitle"), DropDownList)
Dim AdFullName As TextBox = DirectCast(myRepeater.Items(i).FindControl("AdFullName"), TextBox)
selectedAdTitle = AdTitle.Text
enteredAdFullName = AdFullName.Text
cmd.Parameters("@AdTitle").Value = selectedAdTitle
cmd.Parameters("@AdFullName").Value = enteredAdFullName
SQL = ""
SQL = SQL & "INSERT INTO InsuredPersons (TransactionID,Title,FullName) VALUES ("
SQL = SQL & "@TransactionID,"
SQL = SQL & "@AdTitle,"
SQL = SQL & "@AdFullName"
SQL = SQL & ")"
cmd.CommandText = SQL
cmd.Connection = db
cmd.ExecuteNonQuery()
Next
AdTitle 和 AdFullName 似乎没有带来价值观。没有错误,因此他们发现控件正常。下面是 ASPX 文件代码。
<asp:Repeater ID="myRepeater" runat="server">
<ItemTemplate>
<asp:DropDownList ID="AdTitle" runat="server">
<asp:ListItem Selected="True" Value="" Text=""/>
<asp:ListItem Selected="False" Value="Miss" Text="Miss"/>
<asp:ListItem Selected="False" Value="Ms" Text="Ms"/>
<asp:ListItem Selected="False" Value="Mrs" Text="Mrs"/>
<asp:ListItem Selected="False" Value="Mr" Text="Mr"/>
<asp:ListItem Selected="False" Value="Other" Text="Other"/>
</asp:DropDownList>
<asp:TextBox ID="AdFullName" runat="server"></asp:TextBox>
</ItemTemplate>
编辑:
转发器是在页面加载时构建的
Dim repeatTimes((TotalAdInsured - 1)) As Integer
myRepeater.DataSource = repeatTimes
myRepeater.DataBind()
DirectCast 在按钮单击时完成
Protected Sub continueButtonDetails_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles continueButtonDetails.Click
答案:必须将 IsPostback 放在中继器构造周围。
If Not IsPostBack() Then
Dim repeatTimes((TotalAdInsured - 1)) As Integer
myRepeater.DataSource = repeatTimes
myRepeater.DataBind()
End If