[英]Trying to access only one textbox field inside a repeater template
If (dr.Read) Then
Dim thread As Integer
thread = Convert.ToInt32(dr(0).ToString())
For Each rItem As RepeaterItem In Repeater1.Items
Dim txtBox As HtmlInputText = DirectCast(rItem.FindControl("messtxt"), HtmlInputText)
If Not IsNothing(txtBox) Then
Dim messtxta As String = txtBox.Value
cmd2 = New OleDbCommand("INSERT INTO messages(content) VALUES('" & messtxta.Replace("'", "''") & "')", con)
cmd2.Connection = con
cmd2.ExecuteNonQuery()
End If
Next
Response.Redirect("pals.aspx")
The above code works finely for inserting purposes. 上面的代码可以很好地用于插入目的。 Except: The problem is, if the repeater repeats x number of times, there will be x number of inserts from the textbox, out of which one will be the one I entered. 例外:问题是,如果中继器重复x次,则文本框中将有x个插入,其中一个是我输入的。
I only want it to insert one time. 我只希望它插入一次。 Please help. 请帮忙。
If (dr.Read) Then
Dim thread As Integer
Dim txtBox As HtmlInputText
Dim messtxta As String
thread = Convert.ToInt32(dr(0).ToString())
For Each rItem As RepeaterItem In Repeater1.Items
txtBox = DirectCast(rItem.FindControl("messtxt"), HtmlInputText)
If Not IsNothing(txtBox) Then
IF txtBox.Value.Length > 0 THEN
messtxta = txtBox.Value
END IF
End If
Next
cmd2 = New OleDbCommand("INSERT INTO messages(content) VALUES('" & messtxta.Replace("'", "''") & "')", con)
cmd2.Connection = con
cmd2.ExecuteNonQuery()
Response.Redirect("pals.aspx")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.