用户操作
[即时聊天] [发私信] [加为好友]
FansID:fanenmin
52518次访问,排名2232,好友33人,关注者30人。
CSDN网友奥运大联欢,为体育健儿喝彩!
fanenmin的文章
原创 162 篇
翻译 0 篇
转载 81 篇
评论 3 篇
Fans的公告
中国万网代理商(id:20267350) 专业域名注册、虚拟主机、主机托管、企业邮箱、网站建设、排名推广、企业短信、在线支付平台等服务价格低廉。 QQ:116726994 MSN:fanenmin@hotmail.com mail:fanenmin@163.com
最近评论
syptodd:不错 呵呵 谢谢赐教啊
fanenmin:qq
baoruiyang:我正需要这个代码,能不能写的详细点,谢谢
文章分类
收藏
    相册
    my photo
    安家置业
    新浪房产_新浪网
    存档
    软件项目交易
    订阅我的博客
    XML聚合  FeedSky
    订阅到鲜果
    订阅到Google
    订阅到抓虾
    订阅到BlogLines
    订阅到Yahoo
    订阅到GouGou
    订阅到飞鸽
    订阅到Rojo
    订阅到newsgator
    订阅到netvibes

    转载 DataList嵌套终于成功_07.7.25感谢csdn上的朋友收藏

    新一篇: .net身份验证方案(防止重复登陆,session超时)  | 旧一篇: 不能切换设计视图问题

    两个表tb_newsKind,tb_article,表1存的是栏目类别kindID,kindName依次存储的是栏目的编号和名称,如34是新闻播报,其子栏目为35时事新闻和36整点新闻两者的parentID都为34)。
     页面接收传入的一级栏目的kindID来调用它的二级栏目DataList1一行两列的循环显示kindName(kindID)已经实现,问题嵌套的DataList2需要根据DataList1获取的kindID来读取tb_article表中的新闻(tb_article中typeID为nvarchar型比如值为 |34|35|,表示该条记录是属于新闻播报栏目下时事新闻)以列表形式显示在对应的栏目下如:
    新闻播报(35)            时事新闻(36)
    1.**                1.**
    2.**                2.**
    一行两列的循环,新闻播报下面的1,2记录根据35从tb_article表中筛选typeID like '%35%' 得到!
    cs页面中现只绑定好了DataList1的数据源,请问DataList2该如何接收DataList1的kindID的值进行绑定??

    正确代码如下:
    aspx代码如下:  最主要的是看子DataList的DataSource事件的绑定


       <!--主DataList开始-->
                <asp:DataList ID="DataList1" runat="server"  DataKeyField = "kindId" Font-Bold="False" Font-Italic="False"
                    Font-Overline="False" Font-Strikeout="False" Font-Underline="False" CellPadding="0" RepeatDirection="Horizontal" RepeatColumns="2">
                    <ItemTemplate>
                    <!--tb1 start--><table width="212" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td valign="top">
       <table width="212" height="200" border="0" align="center" cellpadding="0" cellspacing="0">
                <tr>
                  <td height="36" valign="bottom" background="images/cunct_1_01.gif"><table width="262" height="25" border="0" align="right" cellpadding="0" cellspacing="0">
                    <tr>
                      <td width="102"><div align="center" class="f">
                        <asp:Label ID="Label2" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.kindName") %>'></asp:Label>
                        </div></td>
                      <td width="101"></td>
                      <td width="59"><div align="center"><a href='<%#"more.aspx?typeid="+DataBinder.Eval(Container.DataItem,"kindId") %>' class="bb" target="_self"><img src="images/cunct_1_more.gif" width="33" height="10" border="0"></a></div></td>
                    </tr>
                  </table></td>
                </tr>
                <tr>
                  <td height="158" valign="top" background="images/cunct_1_02.gif">
                  <!--1start--><table width="270" border="0" align="center" cellpadding="0" cellspacing="0">
                    <tr>
                      <td colspan="2" style="height: 10px"></td>
                    </tr>
                    <tr>
                        <td colspan="5" valign="top" style="padding-left:10px;">          /*一定要注意这个<td>不小心网页布局就会坏了*/
                   
    <asp:DataList ID="DataList2" runat="server" CellPadding="1" CellSpacing="3" RepeatDirection="Vertical" RepeatColumns="1"   DataSource='<%# GetTitleID(DataBinder.Eval(Container.DataItem, "kindId").ToString()) %>'>
                        <ItemTemplate>
                        <table width="100%" border="0" cellspacing="0" cellpadding="0">
                            <tr>
                             <td width="16" height="20"><div align="center"><img src="images/shipin_dian.gif" width="4" height="4" /></div></td>
                             <td width="280" height="20"><a href='<%#"info.aspx?id="+DataBinder.Eval(Container.DataItem,"newID") %>' class="bb" target="_blank"><asp:Label ID="Label3" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.title") %>'></asp:Label></a></td>
                            </tr>
                        </table>
                        </ItemTemplate>
                    </asp:DataList>
                       </td></tr> 
                  </table><!--1end-->
                  </td>
                </tr>
        <tr>
                <td height="6" background="images/shipin_z01.gif"><img src="images/cunct_1_03.gif" width="290" height="20" /></td>
              </tr>
            </table>
       </td>
              </tr>
            </table><!--tb1 end-->
                    </ItemTemplate>
                </asp:DataList><!--主DataList结束--> 

    cs页面代码如:
     
    public DataView GetTitleID(string kindId)
        {
            SqlConnection cn = new SqlConnection("server=.;uid=sa;pwd=sa;database=db_nxt");
            SqlDataAdapter da = new SqlDataAdapter("select top 6 * from tb_article where  TypeId like
    '%'+@kindId+'%' ",cn);
            da.SelectCommand.Parameters.Add("@kindId", SqlDbType.VarChar, 11).Value = kindId;
            DataSet ds = new DataSet();
            cn.Open();
            da.Fill(ds);
            cn.Close();
            return ds.Tables[0].DefaultView;
        }

     Page_Load里面不用写这个绑定的相关调用,大功造成了。谢谢大家,这个问题拖了我3天不已啊……今天突然又看了看朋友给我回的贴子,做出来了。呵呵
     

    发表于 @ 2007年07月27日 15:44:00|评论(loading...)|编辑

    新一篇: .net身份验证方案(防止重复登陆,session超时)  | 旧一篇: 不能切换设计视图问题

    评论

    #baoruiyang 发表于2007-10-01 17:50:24  IP: 218.59.179.*
    我正需要这个代码,能不能写的详细点,谢谢
    发表评论  


    当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
    Csdn Blog version 3.1a
    Copyright © Fans