Hi
Thanks to help from the forum, my nested gridview now looks like this:
Index.aspx
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ERMINFINITYConnectionString %>"
SelectCommand="SELECT CI_CriticalIssues.issueid, CI_CriticalIssues.criticalissue, CI_CriticalIssues.issueowner, CI_Results.resultid, CI_Results.issueid AS Expr1, CI_Results.result, CI_Steps.stepid, CI_Steps.resultid AS Expr2, CI_Steps.step, CI_Steps.status, CI_Steps.stepdue, CI_Steps.review FROM CI_CriticalIssues INNER JOIN CI_Results ON CI_CriticalIssues.issueid = CI_Results.issueid INNER JOIN CI_Steps ON CI_Results.resultid = CI_Steps.resultid"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
OnRowDataBound="GridView1_RowDataBound" DataKeyNames="issueid" >
<Columns>
<asp:BoundField DataField="criticalissue" HeaderText="Critical Issue"/>
<asp:BoundField DataField="issueowner" HeaderText="Issue Owner"/>
<asp:TemplateField>
<ItemTemplate>
<asp:GridView ID="childGV1" runat="server" DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("relation12") %>' AutoGenerateColumns="false"
OnRowDataBound="childGV1_rowDataBound" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Label ID="label11" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "[\"resultid\"]")%>'></asp:Label>
<%# DataBinder.Eval(Container.DataItem, "[\"issueid\"]")%>
<%# DataBinder.Eval(Container.DataItem, "[\"result\"]")%> </ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:GridView ID="childGV2" runat="server" AutoGenerateColumns="true" >
<Columns>
<asp:TemplateField>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "[\"stepid\"]") %>
<%# DataBinder.Eval(Container.DataItem, "[\"resultid\"]") %>
<%# DataBinder.Eval(Container.DataItem, "[\"step\"]") %>
<%# DataBinder.Eval(Container.DataItem, "[\"status\"]") %>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView> Index.aspx.cs
public partial class Index : System.Web.UI.Page
{
DataSet ds = new DataSet();
static string connstr = ConfigurationManager.ConnectionStrings["ERMINFINITYConnectionString"].ToString();
SqlConnection con = new SqlConnection(connstr);
public int count = 0;
public int cnt = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindSet();
}
public void BindSet()
{
SqlDataAdapter cmd1 = new SqlDataAdapter("select * from CI_CriticalIssues", con);
DataSet ds = new DataSet();
cmd1.Fill(ds, "exam1_k");
count = ds.Tables["exam1_k"].Rows.Count;
SqlDataAdapter cmd2 = new SqlDataAdapter("select * from CI_Results", con);
cmd2.Fill(ds, "exam2_k");
cnt = ds.Tables["exam2_k"].Rows.Count;
SqlDataAdapter cmd3 = new SqlDataAdapter("select stepid, resultid, step, status from CI_Steps", con);
cmd3.Fill(ds, "exam3_k");
ds.Relations.Add("relation12", ds.Tables["exam1_k"].Columns["issueid"], ds.Tables["exam2_k"].Columns["issueid"]);
ds.Relations.Add("relation23", ds.Tables["exam2_k"].Columns["resultid"], ds.Tables["exam3_k"].Columns["resultid"]);
GridView1.DataSource = ds.Tables["exam1_k"];
GridView1.DataBind();
con.Close();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{ }
protected void childGV1_rowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataSet ds = new DataSet();
GridView gv12 = (GridView)e.Row.FindControl("childGV2");
Label lblFind = (Label)e.Row.FindControl("label11");
if (gv12 != null && lblFind != null)
{
using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ERMINFINITYConnectionString"].ConnectionString))
{
using (SqlDataAdapter da = new SqlDataAdapter("select * from CI_Steps where resultid = " + Convert.ToInt32(lblFind.Text), con))
{
da.Fill(ds, "FinalTab");
if (ds.Tables["FinalTab"].Rows.Count > 0)
{
gv12.DataSource = ds.Tables["FinalTab"].DefaultView;
gv12.DataBind();
}
}
}
}
}
}
protected void OnRowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].CssClass = "hiddencol";
}
else if (e.Row.RowType == DataControlRowType.Header)
{
e.Row.Cells[0].CssClass = "hiddencol";
}
}
}
This displays a nested gridview containing a critical issue, the expected results and the steps to ensure the results are attained. I need to hide the following columns, but still have the table use their values: issueid, resultid and stepid. How do I do that? I would also appreciate info on how I can add edit and update capabilities to the gridview to conform with the rest of the code.
Please forgive the newbness, but I have exceedingly little experience with code.