473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Nested GridView not binding

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):

Expand|Select|Wrap|Line Numbers
  1. <asp:GridView ID="GridViewMain" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999"
  2.     BorderStyle="None" Font-Names="Arial" BorderWidth="1px" CellPadding="3" DataSourceID="SqlDataSourceTrainingUnits"
  3.     GridLines="Vertical" DataKeyNames="unit_id" OnRowUpdating="Validate_Data" OnRowCommand="grd_RowCommand"
  4.     ShowFooter="True" OnRowDataBound="GridViewMain_RowDataBound">
  5.     <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
  6.     <Columns>
  7.       <asp:TemplateField HeaderText="ID"> 
  8.         <EditItemTemplate> 
  9.           <asp:TextBox ID="unit_id" runat="server" Width="20px" Text='<%# Bind("unit_id") %>'></asp:TextBox> 
  10.         </EditItemTemplate> 
  11.         <ItemTemplate> 
  12.           <asp:Label ID="unit_id" runat="server" Text='<%# Bind("unit_id") %>'></asp:Label> 
  13.         </ItemTemplate>
  14.       </asp:TemplateField>
  15.       <asp:TemplateField HeaderText="Name">
  16.         <EditItemTemplate> 
  17.           <asp:TextBox ID="unit_name" runat="server" Text='<%# Bind("unit_name") %>'></asp:TextBox> 
  18.         </EditItemTemplate> 
  19.         <FooterTemplate> 
  20.           <asp:TextBox ID="unit_name" runat="server" ></asp:TextBox> 
  21.         </FooterTemplate> 
  22.         <ItemTemplate> 
  23.           <asp:Label ID="unit_name" runat="server" Text='<%# Bind("unit_name") %>'></asp:Label> 
  24.         </ItemTemplate>
  25.       </asp:TemplateField>
  26.  
  27.  
  28.       <asp:TemplateField HeaderText="OtherStuff">
  29.         <ItemTemplate> 
  30.           <asp:GridView ID="GridViewNested" runat="server" AutoGenerateColumns="False" BackColor="White"
  31.             BorderColor="#999999" BorderStyle="None" Font-Names="Arial" BorderWidth="1px" CellPadding="3" 
  32.             DataSourceID='<%# GetDocuments(Convert.ToInt32(Eval("unit_id"))) %>'
  33.             GridLines="Vertical" >
  34.             <Columns>
  35.                 <asp:BoundField DataField="doc_name" HeaderText="Document Name" />
  36.                 <asp:BoundField DataField="version" HeaderText="Version" />
  37.             </Columns>
  38.             <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
  39.             <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
  40.             <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
  41.             <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
  42.             <AlternatingRowStyle BackColor="Gainsboro" />
  43.           </asp:GridView>
  44.         </ItemTemplate>
  45.       </asp:TemplateField>
  46.  
  47.  
  48.     </Columns>
  49.             <RowStyle BackColor="#EEEEEE" ForeColor="Black" />
  50.             <SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
  51.             <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
  52.             <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
  53.             <AlternatingRowStyle BackColor="Gainsboro" />
  54. </asp:GridView>
  55.  
As you can see, the datasource for GridViewMain is an SQL data source and I have declared "unit_id" as the "DataKeyNames" 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:

Expand|Select|Wrap|Line Numbers
  1. protected DataTable GetDocuments(int key)
  2. {
  3.     System.Data.DataTable tbl = new DataTable();
  4.     DataColumn doc_namecol = new DataColumn("doc_name");
  5.     tbl.Columns.Add(doc_namecol);
  6.     DataColumn versioncol = new DataColumn("version");
  7.     tbl.Columns.Add(versioncol);
  8.  
  9.     System.Data.OleDb.OleDbConnection ole1 = new System.Data.OleDb.OleDbConnection();
  10.     ole1.ConnectionString = ConfigurationSettings.AppSettings["Training Connection String"];
  11.     OleDbCommand cmd = ole1.CreateCommand();
  12.     ole1.Open();
  13.     OleDbDataReader dr;
  14.     cmd.CommandText = "select doc_name, version, effective_date from training_documents where unit_id = " + key.ToString();
  15.  
  16.     dr = cmd.ExecuteReader();
  17.     while (dr.Read())
  18.     {
  19.         if ((!dr.IsDBNull(0)) && (!dr.IsDBNull(1))))
  20.         {
  21.             DataRow drow = tbl.NewRow();
  22.             drow["doc_name"] = dr.GetString(0).Trim();
  23.             drow["version"] = dr.GetString(1).Trim();
  24.             tbl.Rows.Add(drow);
  25.         }
  26.     }
  27.  
  28.     dr.Close();
  29.     cmd.Dispose();
  30.     ole1.Close();
  31.     ole1.Dispose();
  32.  
  33.     return tbl;
  34. }
  35.  
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
May 21 '08 #1
3 2625
nateraaaa
663 Expert 512MB
Are you assigning the datatable as the datasource for your nested grid view? Please post the code where you assign the datasource for the nested grid view.

Nathan
May 27 '08 #2
It's right there in the code I listed:

In the nested GridView, the datasource is in the line:
Expand|Select|Wrap|Line Numbers
  1. DataSourceID='<%# GetDocuments(Convert.ToInt32(Eval("unit_id"))) %>'
  2.  
And I have shown the full method for GetDocuments.

In any case, the solution was not forthcoming so I found another way to solve my problem. I assigned the datasource in the codebehind instead.

Thanks anyway.

Robert
May 28 '08 #3
nateraaaa
663 Expert 512MB
It's right there in the code I listed:

In the nested GridView, the datasource is in the line:
Expand|Select|Wrap|Line Numbers
  1. DataSourceID='<%# GetDocuments(Convert.ToInt32(Eval("unit_id"))) %>'
  2.  
And I have shown the full method for GetDocuments.

In any case, the solution was not forthcoming so I found another way to solve my problem. I assigned the datasource in the codebehind instead.

Thanks anyway.

Robert
I believe that gridview DataSourceId expects the value to be set to an instance of SqlDataSource (or other data source type such as ODBC). You were trying to set the DataSourceId = to a datatable. In the code behind this is valid because to set the datasource property of the gridview = to a datatable. Here is a helpful link on binding data usig datasource controls.
http://msdn.microsoft.com/en-us/library/ms228089.aspx

Nathan
May 28 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: hammad.awan_nospam | last post by:
Hello, I am using ASP.NET 2.0. What I have done is nested a gridview inside another column of a gridview using a template data field column declaritively in my web form. Inside this child...
3
by: Martin | last post by:
Hi, I have a very frustrating problem that I have researched for countless hours to no avail. There are many posts asking very similar things, however none usefull in my situation. I am using VS...
0
by: manuel.ricca | last post by:
Hello, I'm trying to create a table with 2 nested gridviews and then a DetailsView on the right. The DetailsView should show the details of the item selected in the 2nd (nested) GridView: My...
5
by: Amit | last post by:
Hello, I have a simple search screen, with two drop-downs and a text box. There's also a GridView control that is using a SqlDataSource control to show the matching results. The SqlDataSource uses...
0
by: Peter Rilling | last post by:
Hi. I am using a GridView to display records from an ObjectDataSource. My middle-tier layer have nested properties, meaning that I have things like Employee.Name.FullName, where Employee is...
0
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
2
by: GISmatters | last post by:
I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files...
6
by: RobertTheProgrammer | last post by:
Hi folks, Here's a weird problem... I have a nested GridView setup (i.e. a GridView within a GridView), and within the nested GridView I have a DropDownList item which has the...
0
by: cmrhema | last post by:
Hi, I have a gridview problem while binding more than two gridviews. I am giving a sample scenario of what I have done so far I have two tables First table: Department , having columns...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.