Reputation: 3132
to make things short, i am writing a web app which implements users and groups. multiple users have multiple groups. that leaves me with three tables: user, group, usergroup.
now i have a webform in which i want to manage groups and their members. for this, i have two gridviews on said form. one is for displaying the groups, another for displaying the members of the selected group.
the group-gridview hast two columns: description and another where a buttonfield resides which says "display members". when the user clicks this button, he will get a list of users based on the selected group in the other gridview.
however, i dont really have a clue how to do this? can you please point me in the right direction here?
here is my code:
<asp:Content ID="content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<h1>Gruppenverwaltung</h1>
<asp:Panel ID="pnlGruppe" ScrollBars="Both" runat="server">
<asp:Button ID="btnNeueGruppe" Text="Neue Gruppe" runat="server" OnClick="btnNeueGruppe_Click" />
<asp:GridView DataKeyNames="GruppenID" OnRowCommand="grdGruppe_RowCommand" ID="grdGruppe" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="Bezeichnung" HeaderText="Bezeichnung" SortExpression="Bezeichnung" />
<asp:ButtonField ButtonType="Button" CommandName="MitgliederAnzeigen" Text="Mitglieder anzeigen" />
<asp:CommandField HeaderText="Archivieren" ButtonType="Button" ShowDeleteButton="true" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Bezeichnung], [GruppenID] FROM [Gruppe] WHERE [Archiviert] != 1"
DeleteCommand="UPDATE Gruppe SET [Archiviert] = 1 WHERE [GruppenID] = @GruppenID"></asp:SqlDataSource>
<asp:Button ID="btnZurueck" Text="Zurück" runat="server" OnClick="btnZurueck_Click" />
</asp:Panel>
<asp:Panel Visible="false" ID="pnlMitglieder" ScrollBars="Both" runat="server">
<asp:GridView ID="grdBenutzer" runat="server" AutoGenerateColumns="false">
</asp:GridView>
<asp:Button ID="Button1" Text="Zurück" runat="server" OnClick="Button1_Click" />
</asp:Panel>
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserAuthentication"] == null)
{
Response.Redirect("Login.aspx");
}
}
protected void btnZurueck_Click(object sender, EventArgs e)
{
Response.Redirect("Datenverwaltung.aspx");
}
protected void btnNeueGruppe_Click(object sender, EventArgs e)
{
Response.Redirect("NeueGruppe.aspx");
}
protected void grdGruppe_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "MitgliederAnzeigen")
{
pnlMitglieder.Visible = true;
pnlGruppe.Visible = false;
}
}
protected void Button1_Click(object sender, EventArgs e)
{
pnlMitglieder.Visible = false;
pnlGruppe.Visible = true;
}
Upvotes: 0
Views: 598
Reputation: 8109
protected void grdGruppe_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "MitgliederAnzeigen")
{
string rowindex = e.CommandArgument as string;//Get Row Index
string str = GridView1.Rows[Convert.ToInt32(rowindex)].Cells[0].Text;
pnlMitglieder.Visible = true;
pnlGruppe.Visible = false;
}
After Geting GroupName in str u can bind ur second grid view according to that hope it will help u
Upvotes: 1