Hi folks,
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):
As you can see, the datasource for GridViewMain is an SQL data source and I have declared "unit_id" as the "DataKeyNam es" parameter, which will be used in the nested GridView. Down in the nested GridView, called GridViewNested, the data source calls a method in the codebehind called GetDocuments.
Code for GetDocuments in the codebehind is as follows:
I've run the above code in debug mode and tbl is being populated with good data, but for unknown reasons, it's not being displayed in the nested GridView. (The main/parent GridView displays just fine).
Any help is greatly appreciated.
Robert
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):
Code:
<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:
Code:
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
Comment