在asp.net中编号嵌套转发器

时间:2016-03-31 05:34:55

标签: asp.net

我正在研究一个嵌套的转发器概念,无法得到以下提到的细节的答案。

我想在内部中继器上编号,我试了一下 <%#Container.ItemIndex + 1%>但它没有帮助。还提到下面的代码

<div class="tab-pane" id="2">
    <br />
    <div class="row">
        <asp:Repeater ID="rpStateHub" runat="server" OnItemDataBound="rpStateHub_ItemDataBound">
            <ItemTemplate>
                <div class="item">
                    <div class="well">
                         <p class="state">
                        <strong>
                            <asp:Label ID="lblStateHub" runat="server" Text='<%#Eval("St_Name")%>'></asp:Label></strong> 
                        </p>                                                       

                        <asp:Repeater ID="rp1Hub" runat="server">
                            <ItemTemplate>
                                <%# Container.ItemIndex + 1 %>                                                           
                             <p class="Hub"><%#Eval("Hub_Name") %></p>
                            </ItemTemplate>
                        </asp:Repeater>


                    </div>
                </div>
            </ItemTemplate>
        </asp:Repeater>
    </div>
</div>

enter image description here

已附加所需输出的图像。 在此先感谢您的帮助

2 个答案:

答案 0 :(得分:0)

enter image description here

以下是解释我的问题的图片

答案 1 :(得分:0)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using Dotcom.BOL;

public partial class scorpion_express_NetworkSe : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindNetworkState();
            BindNetworkHub();
            BindNetworkBranch();
            BindNetworkService();
        }

    }

    public void BindNetworkState()
    {

        DataSet ds = Branch.GetNetworkState();
        if (ds.Tables[0].Rows.Count > 0)
        {
            rpState.DataSource = ds;
            rpState.DataBind();
        }
    }

    public void BindNetworkHub()
    {

        DataSet ds = Branch.GetNetworkHub();
        if (ds.Tables[0].Rows.Count > 0)
        {
            rpStateHub.DataSource = ds;
            rpStateHub.DataBind();
        }
    }

    public void BindNetworkBranch()
    {

        DataSet ds = Branch.GetNetworkBranch();
        if (ds.Tables[0].Rows.Count > 0)
        {
            rpStateBranch.DataSource = ds;
            rpStateBranch.DataBind();
        }
    }


    public void BindNetworkService()
    {

        DataSet ds = Branch.GetNetworkService();
        if (ds.Tables[0].Rows.Count > 0)
        {
            rpStateService.DataSource = ds;
            rpStateService.DataBind();
        }
    }
    //protected void rpState_ItemDataBound(object sender, RepeaterItemEventArgs e)
    //{
    //    Repeater innerRepeater = (Repeater)e.Item.FindControl("rpHub");
    //    Repeater innerRepeater1 = (Repeater)e.Item.FindControl("rpBranch");
    //    Repeater innerRepeater2 = (Repeater)e.Item.FindControl("rpService");
    //    Label item = (Label)e.Item.FindControl("lblState");
    //    string state = item.Text;

    //    DataSet ds = Branch.getHub(state);
    //    DataSet ds1 = Branch.getBranch(state);
    //    DataSet ds2 = Branch.getService(state);

    //    if (ds.Tables[0].Rows.Count > 0)
    //    {
    //        innerRepeater.DataSource = ds;
    //        innerRepeater.DataBind();            
    //    }
    //    if (ds1.Tables[0].Rows.Count > 0)
    //    {
    //        innerRepeater1.DataSource = ds1;
    //        innerRepeater1.DataBind();
    //    }
    //    if (ds2.Tables[0].Rows.Count > 0)
    //    {
    //        innerRepeater2.DataSource = ds2;
    //        innerRepeater2.DataBind();
    //    }

    //}

    protected void rpStateHub_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Repeater innerRepeater4 = (Repeater)e.Item.FindControl("rp1Hub");

        Label item = (Label)e.Item.FindControl("lblStateHub");
        string state = item.Text;

        DataSet ds3 = Branch.getHub(state);

            if (ds3.Tables[0].Rows.Count > 0)
            {
                innerRepeater4.DataSource = ds3;
                innerRepeater4.DataBind();
            }

    }

    protected void rpStateBranch_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Repeater innerRepeater5 = (Repeater)e.Item.FindControl("rp1Branch");

        Label item = (Label)e.Item.FindControl("lblStateBranch");
        string state = item.Text;

        DataSet ds4 = Branch.getBranch(state);

        if (ds4.Tables[0].Rows.Count > 0)
        {
            innerRepeater5.DataSource = ds4;
            innerRepeater5.DataBind();
        }


    }

    protected void rpStateService_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        Repeater innerRepeater6 = (Repeater)e.Item.FindControl("rp1Serv");

        Label item = (Label)e.Item.FindControl("lblStateService");
        string state = item.Text;

        DataSet ds5 = Branch.getService(state);

        if (ds5.Tables[0].Rows.Count > 0)
        {
            innerRepeater6.DataSource = ds5;
            innerRepeater6.DataBind();
        }


    }
}

HI @Piyush Khatri here is the code behind file