[英]get value from textbox within repeater asp.net c#
I've been trying to get this working for a couple of hours now but nothing from google could help me fix the problem. 我一直试图让这个工作几个小时,但谷歌没有任何东西可以帮助我解决问题。
I have a very simple repeater control: 我有一个非常简单的转发器控件:
<asp:Panel ID="userDefDiv" Visible="false" runat="server">
<asp:Repeater ID="userDefRepeater" EnableViewstate="false" runat="server">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" EnableViewState="false"></asp:TextBox><br/>
</ItemTemplate>
</asp:Repeater>
</asp:Panel>
the userDefDiv panel is inside another panel, which is inside contentPLaceHolder. userDefDiv面板位于另一个面板内,该面板位于contentPLaceHolder中。 the parent panel to userDefDiv does NOT have the "enableviewstate="false"".
userDefDiv的父面板没有“enableviewstate =”false“”。
So. 所以。 Everything on this page happens after a couple of linkbuttons_click.
这个页面上的所有内容都发生在几个linkbuttons_click之后。 so nothing happens during page_load.
所以在page_load期间没有任何反应。 And after i click another linkbutton i want to get the data from the different textboxes that is within the repeater.
在我点击另一个链接按钮后,我想从转发器内的不同文本框中获取数据。
C# code: C#代码:
This is the code to create all the repeater items. 这是创建所有转发器项的代码。
public void createUserDef()
{
DataTable userDefData;
userDefData = ..... (data from Database.)
userDefDiv.Visible = true;
userDefRepeater.DataSource = userDefData;
userDefRepeater.DataBind();
}
The code for the linkbutton: linkbutton的代码:
protected void linkButton_Click(object sender, EventArgs e)
{
createUserDef();
Label2.Visible = true;
foreach (RepeaterItem item in userDefRepeater.Items)
{
TextBox box = (TextBox)item.FindControl("TextBox1");
string b = box.Text;
Label2.Text += b + " . ";
}
}
As you see i create the repeater once again during the click. 如您所见,我在点击期间再次创建转发器。 But the only thing i can read in label2.
但我唯一可以在label2中阅读。 is aa number of " .", on dot for each textbox.
是一个“。”的数字,在每个文本框的点上。 but the text from the textbox is empty.. What am I doing wrong??
但是文本框中的文字是空的..我做错了什么?
thanks for reading! 谢谢阅读! Mattias
马蒂亚斯
SOLUTION: 解:
add EnableVIewState="true" to textbox & repeater. 将EnableVIewState =“true”添加到文本框和转发器。
Dont call call dataBind() before you get the values. 在获取值之前不要调用dataBind()。
Thanks! 谢谢!
您需要将EnableViewState设置为“true”,以使链接按钮在转发器中正常工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.