Dear All
I have a GridView and Nested GridView with Records. I want to loop through the GridView, and Hide Some Columns of the Nested GridView based on Who is Actually loged in (this is check by User Email).
![GridView and Nested GridView](http://www.c-app.no/Grid_Nested.jpg)
Below is the script:
NESTED GRIDVIEW:
<asp:GridView ID="GridViewGroup" runat="server" DataKeyNames ="GroupID" OnRowCreated="GridViewGroup_RowCreated"
CODE BEHIND: Method of Nested GridView:
protected void GridViewGroup_RowCreated(object sender, GridViewRowEventArgs e)
{
GridView gvOrders = sender as GridView;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (User.IsInRole("Konferanse_Read") || User.IsInRole("Konferanse_Update") || User.IsInRole("Konferanse_Delete"))
{
string constr = ConfigurationManager.ConnectionStrings["DatabaseVestConnectionString1"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
SqlCommand cmd;
con.Open();
string courseId = GridView1.DataKeys[0].Values["CourseID"].ToString();
string checkChildOwner = "SELECT AdminOfficerOfCaseEmail FROM konferanse_Register WHERE CourseID =@CourseID";
cmd = new SqlCommand(checkChildOwner, con);
cmd.Parameters.AddWithValue("@CourseID", courseId);
string valueChildOwner = cmd.ExecuteScalar() as string;
MembershipUser memberEmail = Membership.GetUser();
string AdminEmail = memberEmail.Email.Trim();
if (valueChildOwner != null && !valueChildOwner.Equals(AdminEmail))
{
gvOrders.Columns[1].Visible = false;
gvOrders.Columns[3].Visible = false;
gvOrders.Columns[4].Visible = false;
}
con.Close();
}
}
}
The above solution only works for one records of Main GridView.
How to resolve the issue?
Many thanks in advance