【问题标题】:Add a user row to an existing grid or table on button click在按钮单击时将用户行添加到现有网格或表格
【发布时间】:2013-07-20 02:00:59
【问题描述】:

我创建了一个包含一个 GridView 和一个表单的页面。我的 GridView 工作正常。 我的表单有一个用于用户名或电子邮件地址的文本框和一个提交按钮。此表单也可以正常工作。

在此表单下方,我需要创建一个表格或网格来存储每个添加的用户名和电子邮件。 如何创建此表,以便为每个 btnSendUser_OnClick 事件添加一行?此表不得删除先前插入的行。 我的表格现在只显示一行(最近的)。

我的aspx

<asp:GridView ID="GridView" runat="server" AutoGenerateColumns="false" GridLines="None"
        CssClass="table table-bordered table-striped">
        <Columns>
            <asp:BoundField DataField="AccessGroup" HeaderText="Access Group" />
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Business Justification">
                <ItemTemplate>
                    <asp:TextBox ID="txtJustBuss" runat="server" Height="17px" Width="150px"></asp:TextBox>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:Label ID="lblUserAdd" runat="server" Font-Bold="true" Text="Add User - (Email or User Name)"></asp:Label>
    <br />
    <asp:TextBox ID="txtUserAdd" runat="server" Height="17px" Width="150px"></asp:TextBox>
    <asp:Label ID="lblError" runat="server" class="control-label" for="inputError" Visible="false">Input with error</asp:Label>
    <asp:Button ID="btnAddUser" class="btn" runat="server" Font-Bold="true" Text="Add User"
        OnClick="btnSendUser_OnClick" />
    <br />
    <br />
    <table id="tblUsers" class="table table-bordered table-striped" runat="server" visible="false">
        <tbody>
            <tr>
                <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", "amsuser", "xx");
    UserPrincipal insUserPrincipal = UserPrincipal.FindByIdentity(insPrincipalContext, LoginInfo);

    if (insUserPrincipal == null)
    {
        lblError.Visible = true;
    }

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

【问题讨论】:

    标签: c# asp.net .net


    【解决方案1】:

    您应该使用旨在处理值集合的组件 - 例如另一个网格。

    如果太重,您可以像这样更新标签:

    lblUser.Text = lblUser.Text 
                 + insUserPrincipal.GivenName + " " + insUserPrincipal.Surname
                 + "<br />";
    lblEmail.Text = lblEmail.Text
                  + insUserPrincipal.EmailAddress
                  + "<br />";
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多