2013-07-18 169 views
-1

我在我的頁面中有一張表,列出了用戶和電子郵件,當用戶發送這些信息時 我如何讓這個表格爲每個帖子添加一行而不刪除其他行?在表格中自動添加行HTML

我的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; 
     } 
    } 
} 

回答

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); 
+0

韓國社交協會!我在哪裏添加此代碼? – CaioVJesus89

+0

高興地幫助你,在btnSendUser_OnClick結束時 –

+0

抱歉,沒有爲每個「btnSendUser_OnClick」添加一行。它取代了我上一行和下一行的價值,寫下同樣的東西。我通過兩行獲得相同的信息。它只創建一個列信息(「用戶名」)。 – CaioVJesus89

0

這將是一些可能的解決方案之一:

  1. Store中的集合
  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>