如何在listview中获取文本框的值

本文关键字:取文本 获取 listview | 更新日期: 2023-09-27 18:09:11

            <asp:ListView runat="server" ID="lvAttachments" ItemPlaceholderID="ph" OnItemDataBound="lvAttachments_ItemDataBound">
                <LayoutTemplate>
                    <asp:PlaceHolder ID="ph" runat="server"></asp:PlaceHolder>
                </LayoutTemplate>
                <ItemTemplate>
                                <asp:LinkButton runat="server" ID="btnReject" OnClick="btnReject_Click"></asp:LinkButton>
                                <asp:TextBox runat="server" ID="tbReason" CssClass="textbox" TextMode="MultiLine"></asp:TextBox>
                </ItemTemplate>
            </asp:ListView>

我的问题是:如何从文本框中获取文本,而btnReject单击动作?

protected void btnReject_Click(object sender, EventArgs e)
{
    LinkButton btnReject = (LinkButton)sender;
    // how to get tbReason.Text from this item?
}

编辑:

问题解决!我们只需要添加Page_Load代码来防止重新加载listview和清除文本框:)

http://forums.asp.net/t/1712482.aspx/1

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        lvAttachments.DataSource = tAttachmentBO.getAttachmentsToAccept();
        lvAttachments.DataBind();
    } 
  }

如何在listview中获取文本框的值

像这样应该可以工作

我在ipad上,所以为任何错误道歉

TextBox txt = (TextBox)btnReject.Parent.FindControl("tbReason")