日期:2014-05-18  浏览次数:20429 次

datalist嵌套绑定值
两个datalist 一个DataList1一个DataList2
2嵌套在1里面,1绑定表1的数据,2绑定表2的值
实现DataList1数据绑定很容易,DataList2绑定数据就遇到困难了


希望大家给点思路,有代码更好

------解决方案--------------------
在dl1的itemdatabound事件中,findcontrol(“dl2”)
然后绑定,绑定的时候还可以用上dl1的数据项
------解决方案--------------------
HTML code

        <asp:DataList ID="DataList1" runat="server" Width="100%" onitemdatabound="DataList1_ItemDataBound" 
                                       onitemcommand="DataList1_ItemCommand">
         <ItemTemplate>
         <table style="width:100%; height: 25px;"; cellpadding="0" cellspacing="0">
            <tr>
            <td class="td_line" width="35%">
                <span class="icon">
                    <asp:LinkButton ID="lbtnShow1" runat="server" CommandName="Show">+</asp:LinkButton>
                <a target="_blank" href='ProjectView.aspx?proID=<%#DataBinder.Eval(Container,"DataItem.ProjectID") %>&type=2'>
                <%#GetStringPartContent(DataBinder.Eval(Container, "DataItem.ProjectName").ToString(), 30, true)%></a>
                </span> 
            </td>
            <td width="15%" class="td_line" align="center"><%#DataBinder.Eval(Container, "DataItem.StartTime").ToString()%></td>
            <td width="10%" class="td_line" align="center"><%#DataBinder.Eval(Container, "DataItem.ProjectPrincipal")%></td>
            
            <td width="20%" class="td_line" align="center">
               <asp:Label ID="Label1" runat="server" ToolTip='<%#DataBinder.Eval(Container, "DataItem.Participate") %>'
                Text='<%#GetStringPartContent(DataBinder.Eval(Container, "DataItem.Participate").ToString(), 10, true)%>'></asp:Label></td>
            <td width="20%" class="td_line" align="center">
                <asp:Label ID="lblRights" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.rights")%>' Visible="false"></asp:Label>
                <asp:LinkButton ID="lbtnFile" runat="server" CommandName="FileList" ToolTip="文件列表"><img src="../../images/list.jpg" border="0"/></asp:LinkButton>&nbsp;
                
                <asp:Label ID="lblProID" runat="server" Visible="false" Text='<%#DataBinder.Eval(Container,"DataItem.ProjectID") %>'></asp:Label>
                <asp:LinkButton ID="lbtnUpdate" runat="server" CommandName="Update" ToolTip="修改"><img src="../../images/editor.jpg" border="0"></asp:LinkButton> &nbsp;
               </td>
            </tr>
            </table>
            <div id="Div1" name="Div1" style="display:block; width:98%; margin-left:10px;">
             <asp:DataList ID="DataList2" runat="server" Width="100%" BackColor="#EEF7FB"
                 onitemdatabound="DataList1_ItemDataBound"
                    onitemcommand="DataList1_ItemCommand">
             <ItemTemplate>
                <table style="width:100%; height: 25px;"; cellpadding="0" cellspacing="0">
                <tr>
                <td class="td_line" width="3