Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Embed gridview in datalist

Posted on 2014-12-18
7
Medium Priority
?
72 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 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