Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9056145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T14:07:32+00:00 2026-06-16T14:07:32+00:00

I have two data lists in my page and one of them is nested

  • 0

I have two data lists in my page and one of them is nested in the other one.
I would like to give their data sources in run time during page load event, but my inner data list doesn’t show the value of the data table and I don’t know how to set my inner data lists data source to data table in run time.

I have searched a lot about it but I couldn’t find useful information.
Please help me.

In the page I would like to show which user bought which products, show the quantity and price of each product and show some information about paid index. Like index number or index bank name.
The problem is, for one index number I can have several products. For showing the related products to each index number I used nested data list.
In my first data list now my outer (parent) data list can show the information but the inner data list which should show the products information does not show any thing.

I really need help

This is my code:

  <asp:DataList ID="outerDataLiat" runat="server" RepeatColumns="1" 
            BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid"    BorderWidth="3px" 
            CellPadding="4" CellSpacing="2" ForeColor="Black" GridLines="Both"  DataKeyField="idfromIndex" OnItemDataBound="DataList1_ItemDataBound" />
            <FooterStyle BackColor="#CCCCCC"  />;
            <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
        <ItemStyle BackColor="White" />
        <ItemTemplate />           
    <fieldset>

    <legend&gt>customer information&lt</legend&gt>
    <table style="width: 100%;"/>
     <tr>
      <td>
     &nbsp;customer code:
    </td>
     <td>
                    &nbsp;<asp:Label ID="Label1" runat="server" Text='<%# Eval("idFromUsers") %>'</asp:Label>
             </td>;

                 <td>
                    &nbsp;telephone:
                </td>
                <td>
                    &nbsp;<asp:Label ID="Label2" runat="server" Text='<%# Eval("user_phone") %>'></asp:Label>
                </td>

            </tr>
            <tr>
                <td>
                    &nbsp; customer name :
                </td>
                <td>
                    &nbsp;<asp:Label ID="Label3" runat="server" Text='<%# Eval("user_name") %>'></asp:Label>
                </td>
                <td>
                    &nbsp;cellphone number:
                </td>
                <td>
                    &nbsp;<asp:Label ID="Label4" runat="server" Text='<%# Eval("user_cellphone") %>'></asp:Label>
                </td>
            </tr>
            <tr>
                <td>
                    &nbsp; customer familly name :
                </td>
                <td>
                    &nbsp;<asp:Label ID="Label5" runat="server" Text='<%# Eval("user_familly") %>'></asp:Label>
                </td>
                <td>
                    &nbsp;email :
                </td>
                <td>
                   &nbsp;<asp:Label ID="Label6" runat="server" Text='<%# Eval("user_email") %>'></asp:Label>
                </td>
            </tr>

        </table>

    </fieldset>
    <fieldset>
    <legend>Index Information</legend>
      <table style="width: 100%;">
          <asp:Label ID="hiddenLable" runat="server" Text='<%# Eval("idfromIndex") %>' Visible="false"></asp:Label>
            <tr>
                <td>
                    &nbsp;Index number :
                </td>
                <td>
                    &nbsp;<asp:Label ID="Label7" runat="server" Text='<%# Eval("IndexNO") %>'></asp:Label>
                </td>
                <td>
                    &nbsp;date of index :
                </td>
                <td>
                    &nbsp;<asp:Label ID="Label8" runat="server" ></asp:Label>
                </td>
                <td>
                    &nbsp;bank name:
                </td>
                <td>
                    &nbsp;<asp:Label ID="Label9" runat="server" Text='<%# Eval("bankName") %>'></asp:Label>
                </td>
            </tr>

        </table>

    </fieldset>
    <fieldset>
    <legend>purchased products</legend>
    <asp:DataList ID="innerDataLiat" runat="server" RepeatColumns="1" 
            BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" 
            CellPadding="4" CellSpacing="2" ForeColor="Black" GridLines="Both" OnItemDataBound="DataList2_ItemDataBound"  >
            <FooterStyle BackColor="#CCCCCC"  />
            <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
            <ItemStyle BackColor="White" />
        <ItemTemplate >
        <table style="width: 100%;" id="tbl1"></table>
       <table style="width: 100%;">
            <tr>
                <td>
                    &nbsp;product name :
                </td>
                <td>
                    &nbsp;<asp:Label ID="Label10" runat="server" Text=""></asp:Label>
                </td>
                <td>
                    &nbsp;quantity:
                </td>
                <td>
                    &nbsp;<asp:Label ID="Label11" runat="server" Text=""></asp:Label>
                </td>
                <td>
                    &nbsp;unit price of each product :
                </td>
                <td>
                    &nbsp;<asp:Label ID="Label12" runat="server" Text=""></asp:Label>
                </td>
               <td>
                    &nbsp;Total Amount:
                </td>
                <td>
                &nbsp;<asp:Label ID="Label13" runat="server" Text=""></asp:Label>

                </td>
            </tr>


        </table>
                   </ItemTemplate> 

        </asp:DataList>

    </fieldset>
    <fieldset><legend>shopping cart Information</legend>
        <table style="width: 100%;">
            <tr>
                <td >
                    &nbsp;Total quantity :
                </td>
                <td>
                    &nbsp;<asp:Label ID="Label14" runat="server" Text=""></asp:Label>
                </td>
              <td>
                    &nbsp;total amount of shopping cart:
                </td>
                <td>
                    &nbsp;<asp:Label ID="Label15" runat="server" Text=""></asp:Label>
                </td>

            </tr>
            <tr>
            <td> &nbsp;date of shopping :</td>
            <td dir="rtl">&nbsp<asp:Label ID="Label16" runat="server" Text='<%# Eval("orderDate") %>'  /></td>
            </tr>

        </table>
        </fieldset>


          <asp:LinkButton ID="LinkButton1" runat="server" CommandName="confirm">confirm</asp:LinkButton>
          &nbsp;
          <asp:LinkButton ID="LinkButton2" runat="server" CommandName="notconfirm">not confirm</asp:LinkButton>
        </ItemTemplate>

            <SelectedItemStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />

        </asp:DataList>


    protected void Page_Load(object sender, EventArgs e)
   {
    if (!IsPostBack)
    {
        getDistinctOrderId();
        doPaging();
    }     
 }
private void getDistinctOrderId()
{
    SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["mobile_storeConnectionString"].ConnectionString);
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = myConnection;
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "SELECT min(id), [idfromIndex] FROM Orders WHERE [idfromIndex] IN(SELECT DISTINCT [idfromIndex] FROM Orders) GROUP BY [idfromIndex] ";
    DataView MyDv = new DataView();

    try
    {
        myConnection.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        DataTable dt = new DataTable();
        dt.Load(dr);
        MyDv = dt.DefaultView;
        for (int i = 0; i &lt; MyDv.Count; i++)
        {
            if (i == MyDv.Count - 1)
            {
                distinctList += MyDv[i][0].ToString();
            }
            else
                distinctList += MyDv[i][0].ToString() + ",";
        }

    }
    catch (Exception EXP)
    {
    }
    finally
    { myConnection.Close(); }
}
 public DataTable getTheData()
 {

 DataSet DS = new DataSet();
 SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString);
        SqlDataAdapter objSQLAdapter = new SqlDataAdapter("select idfromIndex,user_name,user_email,indexNO,bankName,Ispay,user_familly,user_cellphone,orderDate,user_phone,idFromUsers,orderId from factors where orderId IN (" + distinctList + ")", myConnection); objSQLAdapter.Fill(DS, "mobile_store");

    return DS.Tables[0];
 }

  void doPaging()
  {
    //DataTable mydatatable = 
    pagedData.DataSource = getTheData().DefaultView;
    pagedData.AllowPaging = true;
    pagedData.PageSize = 4;

 /* 
 ...
   here I wrote some code to make my outer datalist pagable
 ...
*/


    outerDataLiat.DataSource = pagedData;
    outerDataLiat.DataBind();

}

  protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
 {
    if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
    {
        Label lbl = (Label)e.Item.FindControl("hiddenLable");
        string idfromindex = lbl.Text;
        DataList lst2 = (DataList)e.Item.FindControl("innerDataLiat");
        SqlDataSource ds = new SqlDataSource();
        DataTable mydt = new DataTable();

        dataset t = setinnerDataList(idfromindex);
        tb2 = t;
        int sumqty = 0;
        double sumprice = 0;
        for (int i = 0; i &lt; t.Rows.Count; i++)
        {
            sumprice += Convert.ToDouble(t.Rows[i]["p_price"]) * Convert.ToInt32(t.Rows[i]["qty"]);
             sumqty += Convert.ToInt32(t.Rows[i]["qty"]);
        }
        Label lbl14 = (Label)e.Item.FindControl("Label14");
        lbl14.Text = sumqty.ToString();
        Label lbl15 = (Label)e.Item.FindControl("Label15");
        lbl15.Text = sumprice.ToString();

          Label pname = (Label)lst2.FindControl("pname");
        Label qty = (Label)lst2.FindControl("qty");
        Label price = (Label)lst2.FindControl("unit_price");
        DataRow[] dr = t.Tables[0].Select("idfromIndex = '" + idfromindex + "'");//new DataRow[t.Tables[0].Rows.Count]; //=  //This will select all rows where the Name Column has value MAK
        for (int i = 0; i < t.Tables[0].Rows.Count; i++)
        {
            dr[i] = t.Tables[0].Rows[i];
        }
        for (int i = 0; i < dr.Length; i++)
        {
            pname.Text = dr[i]["pname"].ToString();
            price.Text = dr[i]["p_price"].ToString();
            qty.Text = dr[i]["qty"].ToString();
        }

    }
}

  private dataset setinnerDataList(string idfromindex)
 {

    SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["mobile_storeConnectionString"].ConnectionString);
    SqlCommand cmd = new SqlCommand();
    cmd.Connection = myConnection;
    cmd.CommandType = CommandType.Text;
    cmd.CommandText = "SELECT [pname], [p_price], [idfromIndex], [qty] FROM [factors] WHERE ([idfromIndex] = " + idfromindex + ") ";
    DataView MyDv = new DataView();
    dataset dt = new DataTable();
    try
    {
        myConnection.Open();
        SqlDataReader dr = cmd.ExecuteReader();

        dt.Load(dr);
        dr.Close();

    }
    catch (Exception EXP)
    {


    }
    finally
    { myConnection.Close(); }

    return dt;
 }</pre>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T14:07:33+00:00Added an answer on June 16, 2026 at 2:07 pm

    Thank you AYK for your help, it Worked when I changed it this way:

        protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
       {
       if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
        {
            DataList dls1 = (DataList)sender;
            Label lbl = (Label)e.Item.FindControl("hiddenLable");
            string idfromindex = lbl.Text;
            DataList lst2 = (DataList)e.Item.FindControl("innerDataLiat");
            Panel pnl = (Panel)e.Item.FindControl("Panel1");           
             t = setinnerDataList(idfromindex);
            int sumqty = 0;
            double sumprice = 0;
    
    
            for (int i = 0; i < t.Tables[0].Rows.Count; i++)
            {
                sumprice += Convert.ToDouble(t.Tables[0].Rows[i]["p_price"]) * Convert.ToInt32(t.Tables[0].Rows[i]["qty"]);
                sumqty += Convert.ToInt32(t.Tables[0].Rows[i]["qty"]);
    
            }
            Label lbl14 = (Label)e.Item.FindControl("Label14");
            lbl14.Text = sumqty.ToString();
            Label lbl15 = (Label)e.Item.FindControl("Label15");
            lbl15.Text = sumprice.ToString();
            lst2.DataSource = t;
            lst2.DataBind();
         }
        }  
    
           <asp:DataList ID="innerDataLiat" runat="server" RepeatColumns="1" 
                BackColor="#CCCCCC" 
                CellPadding="4" CellSpacing="2" ForeColor="Black" GridLines="Both" OnItemDataBound="DataList2_ItemDataBound"  >
                <FooterStyle BackColor="#CCCCCC"  />
                <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
                <ItemStyle BackColor="White" />
            <ItemTemplate >
            <table style="width: 100%;" ></table>
            <table style="width: 100%;" id="tbl1">
                <tr>
                    <td>
                        &nbsp;product name:
                    </td>
                    <td>
                        &nbsp;<asp:Label ID="pname" runat="server" Text='<%# Eval("pname") %>'></asp:Label>
                    </td>
                    <td>
                        &nbsp;quantity :
                    </td>
                    <td>
                        &nbsp;<asp:Label ID="qty" runat="server" Text='<%# Eval("qty") %>'></asp:Label>
                    </td>
                    <td>
                        &nbsp;unit price:
                    </td>
                    <td>
                        &nbsp;<asp:Label ID="unit_price" runat="server" Text='<%# Eval("p_price") %>' ></asp:Label>
                    </td>
    
                </tr>
    
    
            </table>
                       </ItemTemplate> 
    
            </asp:DataList>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two data sources: a legacy one (web service) and a database one.
I have data from tests with two lists of parts, called in and out.
I have two Data Centers, each one with replication factor 3. Will write with
i have two data classes which hold only data members(no functions). One is CallTask
i have two data tables with the same structure the first one has one
I have two jQuery autocomplete textboxes on a mvc web page. One that returns
I have two tables in a database. One of them contains the users of
I have two lists on my report page. In report studio, I am trying
I trying asp.net and trying posting data from one page to other. It was
I have two database tables, guestlist and attendance On one HTML page, I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.