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 4037168
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:18:50+00:00 2026-05-20T12:18:50+00:00

I had nested datalist I had two datalist the first for getting gategories and

  • 0

I had nested datalist I had two datalist the first for getting gategories and the second subcategory for category I did my code well and first data list get the categories well but the second datalist didnot get any data and no error found so please any one help me.

ASP

 <div>
    <asp:DataList ID="dlCategory" runat="server">
        <EditItemStyle ForeColor="#CC3300" />
        <AlternatingItemStyle ForeColor="#CC3300" />
        <ItemStyle ForeColor="#CC3300" />
        <SelectedItemStyle ForeColor="#CC3300" />
        <HeaderTemplate>
            <div class="buttn_hed_red">
                &nbsp;</div>
            <div class="buttn_hed_bg">
                <div class="lm7 tm1 buttn_hed_txt">
                    Projectors</div>
            </div>
        </HeaderTemplate>
        <ItemTemplate>
            <div class="buttn_div">
                <div class="buttn_red_sqr">
                    &nbsp;</div>
                <div class="lm5 tm2 buttn_txt">
                    <a href='<%#Eval("ID","Category.aspx?ID={0}") %>' class="buttn_txt">
                        <asp:Label ID="LblCat" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"Category") %>'></asp:Label>
                    </a>
                </div>
            </div>
            <asp:DataList ID="dlSubCategory" runat="server" DataSource='<%# GetSubByCategory(Convert.ToString(Eval("ID")))%>'>
                <EditItemStyle ForeColor="#CC3300" />
                <AlternatingItemStyle ForeColor="#CC3300" />
                <SelectedItemStyle ForeColor="#CC3300" />
                <ItemTemplate>
                    <div class="buttn_div_sub">
                        <div class="lm40 tm2 buttn_txt">

                            <asp:Label ID="Label1" runat="server" Text='<%#DataBinder.Eval(Container.DataItem,"SubCategory") %>'></asp:Label>

                        </div>
                    </div>
                </ItemTemplate>
            </asp:DataList>
        </ItemTemplate>
    </asp:DataList>
</div>

CS CODE

public  DataTable   GetSubByCategory(string   ID)
{
    DataTable dt = new DataTable();

    cls.GetSubCategory(ID);
    return dt;

}

METHOD

public DataTable GetSubCategory(string   Category_Id)
{
    using
    (SqlConnection conn = Connection.GetConnection())
    {
        SqlCommand cmd = new SqlCommand();
        cmd.Connection = conn;
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.CommandText = "SP_GetParentByCategoryID";
        SqlParameter ParentID_Param = cmd.Parameters.Add("@CategoryID", SqlDbType.Int);
        ParentID_Param.Value = Category_Id;
        DataTable dt = new DataTable();
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        da.Fill(dt);
        return dt;
    }
}

PROC

ALTER proc [dbo].[SP_GetParentByCategoryID]
(
@CategoryID int
)

as
select  Cat2.[Name] as "SubCategory" ,Cat2.ParentID
from Categories Cat1
  inner join  Categories Cat2
ON Cat1.ID=Cat2.ParentID
where Cat2.ParentID=@CategoryID
  • 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-05-20T12:18:51+00:00Added an answer on May 20, 2026 at 12:18 pm

    I think you are just returning a blank DataTable.

    Try

    public DataTable GetSubByCategory(string ID)
    {
        return cls.GetSubCategory(ID);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Today I had a discussion with a colleague about nested functions in Javascript: function
I had a model with some nested attributes and needed to add new items
Had an interesting discussion with some colleagues about the best scheduling strategies for realtime
Had a coworker ask me this, and in my brain befuddled state I didn't
I had used Server Explorer and related tools for graphical database development with Microsoft
I had been happily coding along on a decent sized solution (just over 13k
I had a discussion with some colleagues mentioning that there are not too many
I had an idea, if I add a python .py file to my C#
I had to delete all the rows from a log table that contained about
I had the idea of a search engine that would index web items like

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.