Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 嵌套数据列表_Asp.net_Nested Datalist - Fatal编程技术网

Asp.net 嵌套数据列表

Asp.net 嵌套数据列表,asp.net,nested-datalist,Asp.net,Nested Datalist,我有嵌套的数据列表我有两个数据列表第一个用于获取gategories,第二个用于类别的子类别我做得很好,第一个数据列表很好地获取类别,但是第二个数据列表没有获取任何数据,也没有发现错误,所以请任何人帮助我 ASP <div> <asp:DataList ID="dlCategory" runat="server"> <EditItemStyle ForeColor="#CC3300" /> <Alternatin

我有嵌套的数据列表我有两个数据列表第一个用于获取gategories,第二个用于类别的子类别我做得很好,第一个数据列表很好地获取类别,但是第二个数据列表没有获取任何数据,也没有发现错误,所以请任何人帮助我

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>
方法

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

我想您只是返回了一个空白的
数据表

试一试

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
public DataTable GetSubByCategory(string ID)
{
    return cls.GetSubCategory(ID);
}