当前位置:编程学习 > C#/ASP.NET >>

问一下datalist的绑定

这是用datalist绑定的数据
<tr>
<td>
                <table>
                    <tr>
                            <td bgcolor="#FFFFFF"><div align="center"><a href="lymmshow.asp"><img src="images/no.jpg" border="0" /></a></div></td>
                          </tr>
                          <tr>
                            <td height="25" bgcolor="#FFFFFF"><div align="center"><strong><a href="lymmshow.asp">曉麗苑</a></strong></div></td>
                          </tr>
                         </table>
                        </td><td>
                <table>
                    <tr>
                            <td bgcolor="#FFFFFF"><div align="center"><a href="lymmshow.asp"><img src="images/no.jpg" border="0" /></a></div></td>
                          </tr>
                          <tr>
                            <td height="25" bgcolor="#FFFFFF"><div align="center"><strong><a href="lymmshow.asp">祥和苑</a></strong></div></td>
                          </tr>
                         </table>
                        </td>
</tr>
这是一行的,我想怎么样在这一行的下面加上
                                  <tr>
                                <td> </td>
                                <td>
                                    </td>
                              </tr> 这到一行,然后接着绑定? --------------------编程问答-------------------- 没看明白意思 --------------------编程问答-------------------- 给tr加一个id就可以了
或者给talbe加个id --------------------编程问答-------------------- 这样写就行:
ItemTemplate是datalist的模板列,而AlternatingItemTemplate是datalist的交叉绑定列
-------------------------------------------------------------------------------
<asp:DataList ID="DataList1" runat="server">
            <ItemTemplate>
                 <table>
                    <tr>
                        <td bgcolor="#FFFFFF"><div align="center"><a href="lymmshow.asp"><img src="images/no.jpg" border="0" /></a></div></td>
                    </tr>
                    <tr>
                        <td height="25" bgcolor="#FFFFFF"><div align="center"><strong><a href="lymmshow.asp">曉麗苑</a></strong></div></td>
                    </tr>
                  </table>
                  <table>
                    <tr>
                        <td bgcolor="#FFFFFF"><div align="center"><a href="lymmshow.asp"><img src="images/no.jpg" border="0" /></a></div></td>
                    </tr>
                    <tr>
                         <td height="25" bgcolor="#FFFFFF"><div align="center"><strong><a href="lymmshow.asp">祥和苑</a></strong></div></td>
                     </tr>
                   </table>
                              
            </ItemTemplate>
            <AlternatingItemTemplate>
            <table>
                <tr>
                    <td> </td>
                     <td>
                      </td>
                 </tr>
            </table>
            </AlternatingItemTemplate>
        </asp:DataList> --------------------编程问答-------------------- <table>
                    <tr>
                            <td bgcolor="#FFFFFF"><div align="center"><a href="lymmshow.asp"><img src="images/no.jpg" border="0" /></a></div></td>
                          </tr>
                          <tr>
                            <td height="25" bgcolor="#FFFFFF"><div align="center"><strong><a href="lymmshow.asp">曉麗苑</a></strong></div></td>
                          </tr>
<tr>
                                <td> </td>
                                <td>
                                    </td>
                              </tr> 
                         </table>
--------------------编程问答-------------------- 在后台绑定的时候设一个变量,判断一下这个是单行,还是双行,就行了

友情UP一下 --------------------编程问答-------------------- 再说也没有你那么绑定的啊,你那样也显示不出来效果的,应该是这样的,例子:
使用pubs数据库:
HTML:
------------------------------------------------------------
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DataList ID="DataList1" runat="server">
            <ItemTemplate>
                 <table border=1>
                    <tr>
                        <td height="25" bgcolor="#FFFFFF">
                            <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"au_id") %>'></asp:Label></td>
                    </tr>
                  </table>
                  <table>
                    <tr>
                         <td height="25" bgcolor="#FFFFFF">
                             <asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"au_fname") %>'></asp:Label></td>
                     </tr>
                   </table>
                              
            </ItemTemplate>
            <AlternatingItemTemplate>
            <table>
                <tr>
                    <td><asp:Label ID="Label2" runat="server" Text='<%# "分隔行+"+DataBinder.Eval(Container.DataItem,"state") %>'></asp:Label></td>
                 </tr>
            </table>
            </AlternatingItemTemplate>
        </asp:DataList>
    </div>
    </form>
</body>
</html>

C#:
-----------------------------------------------------------------

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlConnection con = new SqlConnection("server=.;uid=sa;pwd=;database=pubs");
            SqlDataAdapter da = new SqlDataAdapter("select * from authors",con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            DataList1.DataSource = ds;
            DataList1.DataBind();
        }
    }

//要从数据库中提取值才行 --------------------编程问答-------------------- 学习,接分,帮顶!
补充:.NET技术 ,  ASP.NET
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,