-1

我的页面中有一个表格,其中列出了用户发送此信息时的用户和电子邮件我如何使此表格为每个帖子添加一行而不删除其他行?

我的 aspx

<table id="tblUsers" class="table table-bordered table-striped">
        <tbody id="tbodyUser">
            <tr>
                <asp:Label ID="lblHeader" Font-Bold="true" runat="server" Visible="false">User to Access</asp:Label>
                <td>
                    <asp:Label ID="lblUser" runat="server" Visible="false"></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblEmail" runat="server" Visible="false"></asp:Label>
                </td>
            </tr>
        </tbody>
    </table>

我的.cs

protected void btnSendUser_OnClick(object sender, EventArgs e)
{
    string LoginInfo = txtUserAdd.Text;
    PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain, "x.com", "amsndrsecuritysqlser", "xxx");
    UserPrincipal insUserPrincipal = UserPrincipal.FindByIdentity(insPrincipalContext, LoginInfo);


    //it's to first post
    if (lblUser.Visible == false && lblEmail.Visible == false)
    {
        if (insUserPrincipal == null)
        {
            lblError.Visible = true;
        }

        else
        {
            lblUser.Visible = true;
            lblEmail.Visible = true;
            lblHeader.Visible = true;
            lblUser.Text = insUserPrincipal.GivenName + " " + insUserPrincipal.Surname;
            lblEmail.Text = insUserPrincipal.EmailAddress;
        }
    }
}
4

2 回答 2

2

您必须添加runat="server"到您的表tblUsers

var row =new System.Web.UI.HtmlControls.HtmlTableRow();
var cell = new System.Web.UI.HtmlControls.HtmlTableCell();
cell.InnerText = "New Cell";
row.Cells.Add(cell);
tblUsers.Rows.Add(row);
于 2013-07-18T18:50:52.233 回答
0

这将是一些可能的解决方案之一:

  1. 将数据存储在集合中
  2. 在每次单击按钮时,更新数据并将其放入会话中
  3. 将会话数据绑定到页面中的中继器(绑定代码必须在 Page_Load 中)

中继器标记将是这样的

 <asp:Repeater ID="Repeater1" runat="server">
    <HeaderTemplate>
        <table id="tblUsers" class="table table-bordered table-striped">
            <tbody id="tbodyUser">
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <asp:Label ID="lblHeader" Font-Bold="true" runat="server" Visible="<% #lblHeaderVisibilty %>">User to Access</asp:Label>
            <td>
                <asp:Label ID="lblUser" runat="server" Visible="<% #lblUserVisibilty %>"></asp:Label>
            </td>
            <td>
                <asp:Label ID="lblEmail" runat="server" Visible="<% #lblEmailVisibilty %>"></asp:Label>
            </td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        </tbody>
    </table>
    </FooterTemplate>
</asp:Repeater>
于 2013-07-18T19:51:47.690 回答