I've got another problem. Basically, I'm trying to use a nested GridView, however the nexted GridView displays no values (even though in debug I'm getting valid values into my DataSet. It's probably a binding issue somewhere, but I'm not sure where.
Here's the ASP (slightly edited to remove verbosity):
Expand|Select|Wrap|Line Numbers
- <asp:GridView ID="GridViewMain" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999"
- BorderStyle="None" Font-Names="Arial" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSourceTrainingUnits"
- GridLines="Vertical" DataKeyNames="unit_id" OnRowUpdating="Validate_Data" OnRowCommand="grd_RowCommand"
- ShowFooter="True" OnRowDataBound="GridViewMain_RowDataBound">
- <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
- <Columns>
- <asp:TemplateField HeaderText="ID">
- <EditItemTemplate>
- <asp:TextBox ID="unit_id" runat="server" Width="20px" Text='<%# Bind("unit_id") %>'></asp:TextBox>
- </EditItemTemplate>
- <ItemTemplate>
- <asp:Label ID="unit_id" runat="server" Text='<%# Bind("unit_id") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="Name">
- <EditItemTemplate>
- <asp:TextBox ID="unit_name" runat="server" Text='<%# Bind("unit_name") %>'></asp:TextBox>
- </EditItemTemplate>
- <FooterTemplate>
- <asp:TextBox ID="unit_name" runat="server" ></asp:TextBox>
- </FooterTemplate>
- <ItemTemplate>
- <asp:Label ID="unit_name" runat="server" Text='<%# Bind("unit_name") %>'></asp:Label>
- </ItemTemplate>
- </asp:TemplateField>
- <asp:TemplateField HeaderText="OtherStuff">
- <ItemTemplate>
- <asp:GridView ID="GridViewNested" runat="server" AutoGenerateColumns="False" BackColor="White"
- BorderColor="#999999" BorderStyle="None" Font-Names="Arial" BorderWidth="1px" CellPadding="3"
- DataSourceID='<%# GetDocuments(Convert.ToInt32(Eval("unit_id"))) %>'
- GridLines="Vertical" >
- <Columns>
- <asp:BoundField DataField="doc_name" HeaderText="Document Name" />
- <asp:BoundField DataField="version" HeaderText="Version" />
- </Columns>
- <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
- <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
- <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
- <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
- <AlternatingRowStyle BackColor="Gainsboro" />
- </asp:GridView>
- </ItemTemplate>
- </asp:TemplateField>
- </Columns>
- <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
- <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
- <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
- <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
- <AlternatingRowStyle BackColor="Gainsboro" />
- </asp:GridView>
Code for GetDocuments in the codebehind is as follows:
Expand|Select|Wrap|Line Numbers
- protected DataTable GetDocuments(int key)
- {
- System.Data.DataTable tbl = new DataTable();
- DataColumn doc_namecol = new DataColumn("doc_name");
- tbl.Columns.Add(doc_namecol);
- DataColumn versioncol = new DataColumn("version");
- tbl.Columns.Add(versioncol);
- System.Data.OleDb.OleDbConnection ole1 = new System.Data.OleDb.OleDbConnection();
- ole1.ConnectionString = ConfigurationSettings.AppSettings["Training Connection String"];
- OleDbCommand cmd = ole1.CreateCommand();
- ole1.Open();
- OleDbDataReader dr;
- cmd.CommandText = "select doc_name, version, effective_date from training_documents where unit_id = " + key.ToString();
- dr = cmd.ExecuteReader();
- while (dr.Read())
- {
- if ((!dr.IsDBNull(0)) && (!dr.IsDBNull(1))))
- {
- DataRow drow = tbl.NewRow();
- drow["doc_name"] = dr.GetString(0).Trim();
- drow["version"] = dr.GetString(1).Trim();
- tbl.Rows.Add(drow);
- }
- }
- dr.Close();
- cmd.Dispose();
- ole1.Close();
- ole1.Dispose();
- return tbl;
- }
Any help is greatly appreciated.
Robert