标题:repeater 嵌套取值 急救啊。。
只看楼主
跳过去
Rank: 8Rank: 8
等 级:贵宾
威 望:20
帖 子:282
专家分:976
注 册:2012-8-13
结帖率:91.3%
已结贴  问题点数:20 回复次数:4 
repeater 嵌套取值 急救啊。。


前台:
<asp:Repeater ID="rptTypeTitle" runat="server" OnItemDataBound="rptTity_OnItemDataBound">
     <ItemTemplate>
     <asp:Label ID="lblID" runat="server" Text=' <%#Eval("ID") %> '></asp:Label>
     <div class="MianPageDiv">
          <table border="2">
                <tr>
                <td colspan="2">
                <%#Eval("TypeName")%></td>
                 
                </tr>
            <asp:Repeater ID="rptPostTity" runat="server">
            <ItemTemplate>
               
            <tr>
            <td style="text-align:center"><b>用户头像</b></td>
            <td>时间</td>
            </tr>
            <tr>
             <td rowspan="2">
             <asp:Image ID="Image1" runat="server" /> <br />用户名称
             </td>
             <td rowspan="2">标题</td>
             </tr>
             </ItemTemplate>
             /asp:Repeater>
            </table>
       </div>
    </ItemTemplate>

后台:
    public void rptTity_OnItemDataBound(object sender,RepeaterItemEventArgs e)
        {
            Repeater rptPostTity = e.Item.FindControl("rptPostTity") as Repeater;
            //Label lblid = e.Item.FindControl("lblID") as Label;
            //int id =Int32.Parse(lblid.Text);
            MianPageManage mian = e.Item.DataItem as MianPageManage;
            int id = 3;
            if (rptPostTity != null)
            {
               
                rptPostTity.DataSource = mian.GetTityName(id
             );
                rptPostTity.DataBind();
            }
        }


要怎么样才能获取到 Label  里的ID值啊?Label  的ID的值是表一的
搜索更多相关主题的帖子: asp 前台 server border 
2012-09-28 15:55
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
得分:20 
public void rptTity_OnItemDataBound(object sender,RepeaterItemEventArgs e)
        {
            Repeater rptPostTity = e.Item.FindControl("rptPostTity") as Repeater;
int id ;
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) {
            Label lblid = e.Item.FindControl("lblID") as Label;
            id =Int32.Parse(lblid.Text);
}
else
{id = 3;
}
            MianPageManage mian = e.Item.DataItem as MianPageManage;
if (rptPostTity != null)
            {
               
                rptPostTity.DataSource = mian.GetTityName(id
             );
                rptPostTity.DataBind();
            }
        }

试试

59ita点com(我就爱TA)
2012-09-28 21:09
belin2000
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:975
专家分:194
注 册:2004-6-2
得分:0 
其实我不建议 嵌套, 能一次解决的,何必用嵌套呢? 查询两个表,不是可以返回两个表的数据吗?用 jion (sql)语句 不是可以很好的返回想要的两个表的数据吗?

[ 本帖最后由 belin2000 于 2012-9-28 21:15 编辑 ]

59ita点com(我就爱TA)
2012-09-28 21:11
qinglong332
Rank: 1
来 自:天津
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-10-10
得分:0 
有些东西,还真得用嵌套控件。
public void rptTity_OnItemDataBound(object sender,RepeaterItemEventArgs e)
{
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType==ListItemType.AlternatingItem)
    {
        Repeater rptPostTity = e.Item.FindControl("rptPostTity") as Repeater;
        Label lblid = e.Item.FindControl("lblID") as Label;
        int id = -1;
        if(int.TryParse(lblid.Text, out id))
        {
            MianPageManage mian = e.Item.DataItem as MianPageManage;     // 这里不解,数据源是泛型?
            if (rptPostTity != null)
            {
                rptPostTity.DataSource = mian.GetTityName(id);
                rptPostTity.DataBind();
            }
        }

        // 如果数据源是DataTable的话,这个地方的ID也可以这么取到吧
        // RepeaterItem rptItem = (RepeaterItem)e.Item;
        // DataRow itemDataRow = (rptItem.DataItem as DataRowView).Row;
        // int id = itemDataRow.Field<int>("ID");
    }
}
2012-10-10 12:07
nielin123
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2012-10-11
得分:0 
使用NamingContainer容器就行了
2012-10-11 14:59



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-382268-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.393098 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved