Solved

Embed gridview in datalist

Posted on 2014-12-18
7
71 Views
Last Modified: 2014-12-27
I have a page that has a gridview embedded inside the itemtemplate of a datalist. Attached is a picture of what it would look like except it is repeating the routing info. Basically every parent job (ie 74807) has sub-jobs (ie 74807-1, 74807-2), and every sub-job and parent job has a field (Top_Lvl_Job) in the database that corresponds to the parent job (see picture). So in the code at the bottom you see the datasource for the datalist pulling every parent job and subjob based on the top_lvl_job field.

screenshot
database
The problem comes with the select command in the datasource for the gridview. I want it to pull the routing information for each job in the loop. You will see some question marks where I think the problem is.

I hope I explained that well.

    <!--Start Datalist Code--> 

    <asp:DataList ID="DataList1" runat="server" DataKeyField="Job" DataSourceID="sdsJobDetails">
        <ItemTemplate>
            <h3>Job Detail for <%# Eval("Job") %></h3>
            <h4>Created By: <%# Eval("Last_Name") %></h4>
           <br />
            <table style="width: 100%;">
                <tr>
                    <td style="width:400px;"><b>Part Number:</b> <%# Eval("Part_Number") %></td>
                    <td style="width:400px;"><b>Date Created:</b> <%# Eval("Order_Date") %></td>
                    <td style="width:400px;"><b>Type:</b> <%# Eval("Type") %></td>
                </tr>
                <tr>
                    <td><b>Revision:</b> <%# Eval("Rev") %></td>
                    <td><b>Quantity Ordered:</b> <%# Eval("Order_Quantity") %></td>
                    <td><b>Make Quantity:</b> <%# Eval("Make_Quantity") %></td>
                </tr>
                <tr>
                    <td><b>Description:</b> <%# Eval("Description") %></td>
                    <td><b>Unit Price:</b> $<%# Eval("Unit_Price") %></td>
                    <td><b>Pick Quantity:</b> <%# Eval("Pick_Quantity") %></td>
                </tr>
                <tr>
                    <td><b>Drawing Name:</b> <%# Eval("Drawing") %></td>
                    <td><b>Prepaid Amount:</b> <%# Eval("Prepaid_Amt") %></td>
                    <td><b>Completed Quantity:</b> <%# Eval("Completed_Quantity") %></td>
                </tr>
                <tr>
                    <td><b>Customer:</b> <%# Eval("Customer") %></td>
                    <td><b>Status:</b> <%# Eval("Status") %></td>
                    <td><b>Shipped:</b> <%# Eval("Shipped_Quantity") %></td>
                </tr>
                <tr>
                    <td><b>Ship Via:</b> <%# Eval("Ship_Via") %></td>
                    <td></td>
                    <td></td>
                </tr>
            </table>

            <!--Start Embedded Gridview Code-->
            
            <h3>Routing Info</h3>
            <br />
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="sdsRouting" ForeColor="#333333">
        <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        <Columns>
            <asp:BoundField DataField="WC_Vendor" HeaderText="Work Center" SortExpression="WC_Vendor" />
            <asp:BoundField DataField="Operation_Service" HeaderText="Service" SortExpression="Operation_Service" />
            <asp:BoundField DataField="Name" HeaderText="Vendor" SortExpression="Name" />
            <asp:BoundField DataField="Sequence" HeaderText="Sequence" SortExpression="Sequence" />
            <asp:BoundField DataField="Est_Run_Hrs" HeaderText="Estimated Hours" SortExpression="Est_Run_Hrs" />
            <asp:BoundField DataField="Act_Run_Hrs" HeaderText="Actual Hours" SortExpression="Act_Run_Hrs" />
            <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
            <asp:BoundField DataField="Job" HeaderText="Job" SortExpression="Job" Visible="False" />
        </Columns>
        <EditRowStyle BackColor="#999999" />
        <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
        <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
        <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
        <SortedAscendingCellStyle BackColor="#E9E7E2" />
        <SortedAscendingHeaderStyle BackColor="#506C8C" />
        <SortedDescendingCellStyle BackColor="#FFFDF8" />
        <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
        </asp:GridView>

            <!--End Embedded Gridview Code-->

        </ItemTemplate>
    </asp:DataList>
    
    <!--End Datalist Code--> 

    <!--Datasource for Gridview-->

        <asp:SqlDataSource ID="sdsRouting" runat="server" ConnectionString="<%$ ConnectionStrings:pppConnectionString %>" SelectCommand="SELECT * FROM [V_Job_Det_Routing] WHERE ([Job] = ???????) ORDER BY [Sequence]">
            <SelectParameters>
                <asp:QueryStringParameter Name="Job" QueryStringField="job" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>

    <!--Datasource for Datalist-->

    <asp:SqlDataSource ID="sdsJobDetails" runat="server" ConnectionString="<%$ ConnectionStrings:pppConnectionString %>" SelectCommand="SELECT * FROM [V_Job_Det_Jobs] WHERE ([Top_Lvl_Job] = @Top_Lvl_Job)">
        <SelectParameters>
            <asp:QueryStringParameter Name="Top_Lvl_Job" QueryStringField="job" Type="String" />
        </SelectParameters>
    </asp:SqlDataSource>
</asp:Content>

Open in new window

0
Comment
Question by:princeservice
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
7 Comments
 

Author Comment

by:princeservice
ID: 40509363
This is beyond aggravating.

After studying more I realize that the datasource for the gridview is looking for a querystring which is not true. I am assuming that the selectparameter should be a controlparameter. I played around a little more and came up with this. Don't know if I am getting close or not. It still does not work

New datasource code

    <asp:SqlDataSource ID="sdsRouting" runat="server" ConnectionString="<%$ ConnectionStrings:pppConnectionString %>" SelectCommand="SELECT * FROM [V_Job_Det_Routing] WHERE ([Job] = @job) ORDER BY [Sequence]">
        <SelectParameters>
            <asp:controlparameter Name="job" ControlID="lblJob"/>
        </SelectParameters>
    </asp:SqlDataSource>

Open in new window


I replaced the text at the top of the page from this:

<h3>Job Detail for <%# Eval("Job") %></h3>

Open in new window


to this:

<h3>Job Detail for <asp:Label ID="lblJob" runat="Server" Text='<%# Eval("Job") %>' /></h3>

Open in new window

0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40509822
Is there a reason that you are using an HTML <table>, instead of a GridView, to render the table?  It looks like you can do the same thing with a simple GridView control.
0
 

Author Comment

by:princeservice
ID: 40510031
I didn't know you could take one row of a table and break it up into three columns with a gridview
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 96

Expert Comment

by:Bob Learned
ID: 40510231
I could see a way where you could use a GridView, with a template column that combines a Header Template for the details, and an Item Template for a nested GridView.

Then, you can set the data source for the nested GridView in the RowCreated event handler.

Here is an example of binding a nested DropDownList to a DataTable:

How to Bind DropDownList in GridView RowDataBound:
http://technico.qnownow.com/how-to-bind-dropdownlist-in-gridview-rowdatabound/

protected void gvProducts_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.DataItem != null)
        {
            //check if is in edit mode
            if ((e.Row.RowState & DataControlRowState.Edit) > 0)
            {
                DropDownList ddlSubCategories = (DropDownList)e.Row.FindControl("ddlSubCategories");
                //Bind subcategories data to dropdownlist
                ddlSubCategories.DataTextField = "SubCategoryName";
                ddlSubCategories.DataValueField = "ProductSubcategoryID";
                ddlSubCategories.DataSource = RetrieveSubCategories();
                ddlSubCategories.DataBind();
                DataRowView dr = e.Row.DataItem as DataRowView;
                ddlSubCategories.SelectedValue = dr["ProductSubCategoryID"].ToString();
            }
        }
    }
}

Open in new window


The more I think about this, though, there is probably not much difference between a GridView, and a DataList for the outer control.  Also, I might still be out in left field somewhere, trying to understand your requirement.
0
 

Author Comment

by:princeservice
ID: 40510275
Not sure how binding to a dropdown list is going to help me.

Basically I want to build a datasource for a gridview that is embedded in a datalist. That datasource is going to use a label in the datalist for the selectparemeter.
0
 

Accepted Solution

by:
princeservice earned 0 total points
ID: 40512907
I have given up on this project.
0
 

Author Closing Comment

by:princeservice
ID: 40519484
No longer working on project
0

Featured Post

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question