이전에 이와 같은 작업을 수행했음을 알았지 만 지금 작동하지 않는 이유는 알 수 없습니다. ListBox에 일부 텍스트 상자가 있습니다. 버튼을 클릭하면 해당 상자에서 텍스트를 읽고 싶습니다 (링크 버튼, 무엇이든).ListView 필드가 게시되지 않음
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 클릭하면 내가 보는 것은 그냥 "말"입니다 :
<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" />
그리고 여기는 관련 코드 숨김 물건입니다. 여기서 내가 뭘 잘못하고 있니?
foreach에서는 lv_bar가 아니어야합니까? –
예, 죄송합니다. 붙여 넣기 전에 실제 코드를 일반화하려고했으나 문제가 아닙니다. –