我知道我以前做过类似的事情,但我不知道为什么它现在不能工作。我有一个ListView与一些文本框。当我点击一个按钮(linkbutton,无论)时,我想从这些框中读出文本。ListView字段没有发布
<asp:ListView runat="server" ID="lv_bar" EnableViewState="true">
<LayoutTemplate>
<table>
<tr>
<th>Foo</th>
</tr>
<tr runat="server" id="itemPlaceholder"></tr>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><asp:LinkButton ID="lb_delete" CausesValidation="false" runat="server" Text="Del" /></td>
<td><asp:TextBox id="txt_foo" runat="server" /></td>
</tr>
</ItemTemplate>
</asp:ListView>
<asp:LinkButton ID="lb_add" CausesValidation="false" runat="server" Text="Add" />
然后这里是相关的代码隐藏的东西:
protected void Page_Load(object sender, EventArgs e)
{
lb_chapter_add.Click += lb_chapter_add_Click;
if (!IsPostBack)
{
lv_chapters.DataSource = new List<Foo>() { new Foo() { Name = "harbl"} };
lv_chapters.DataBind();
}
}
void lb_add_Click(object sender, EventArgs e)
{
foreach (ListViewDataItem item in lv_bar.Items)
{
var txt_foo = (TextBox)item.FindControl("txt_foo");
Response.Write("foo: " + txt_foo.Text);
}
Response.Write("<br />the end");
Response.End();
}
但我所看到的,当我输入一些文字到txt_foo并单击lb_add就是“终结”。我在这里做错了什么?
不应该是lv_bar在foreach中吗? – 2010-01-07 18:45:47
是的,对不起,我试图在粘贴之前概括实际的代码 - 但这不是问题:) – 2010-01-07 18:47:26