我创建了一个包含一个 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;
}
}