用DATALIST应该怎么实现???

解决方案 »

  1.   

    是个机票查询结果返回的页面...
    能不能用DataList中嵌DagaGrid使用..然后在DataGrid中可以使用JS来全部展开或只留一个最小值的一行 
      

  2.   

                                                    <asp:datalist id="DataList1" runat="server" repeatlayout="table" repeatcolumns="3" showheader="false"
                                                        repeatdirection="horizontal" showfooter="false" OnItemDataBound="BoundData" Width="100%">
                                                        <ItemStyle VerticalAlign="Top"></ItemStyle>
                                                        <ItemTemplate>
                                                            <table cellpadding="0" cellspacing="0" width="100%" class="tableBorder" height="20">
                                                                <tr>
                                                                    <td class="column">
                                                                        <asp:TextBox id=txtBox Text='<%# DataBinder.Eval(Container.DataItem,"ForumGroupID")%>' Visible="False" Runat="server">
                                                                        </asp:TextBox><B><A href='Default.aspx?ForumGroupID=<%#DataBinder.Eval(Container.DataItem,"ForumGroupID") %>'>·<%# DataBinder.Eval(Container.DataItem,"Name") %>
                                                                            </A></B>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td class="fh2">
                                                                        <asp:DataGrid id="DataGrid3" runat="server" ShowHeader="False" AutoGenerateColumns="False" BorderWidth="0">
                                                                            <ItemStyle VerticalAlign="Top" CssClass="fh2"></ItemStyle>
                                                                            <Columns>
                                                                                <asp:TemplateColumn>
                                                                                    <ItemTemplate>
                                                                                        [
                                                                                        <asp:HyperLink runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Name") %>' NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.ForumId", "{0}/ShowForum.aspx") %>' ID="Hyperlink7">
                                                                                        </asp:HyperLink>]
                                                                                        <asp:HyperLink runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.subject") %>' NavigateUrl='<%# DataBinder.Eval(Container, "DataItem.postid", "{0}/ShowPost.aspx") %>' ID="Hyperlink8">
                                                                                        </asp:HyperLink>
                                                                                    </ItemTemplate>
                                                                                </asp:TemplateColumn>
                                                                            </Columns>
                                                                        </asp:DataGrid></td>
                                                                </tr>
                                                            </table>
                                                        </ItemTemplate>
                                                    </asp:datalist>private void BindDataList1()
            {
                SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["SiteSqlServer"]);
                SqlCommand comm=new SqlCommand("select ForumGroupID,Name from forums_ForumGroups order by ForumGroupID ",conn);
                conn.Open();
                SqlDataReader rd=comm.ExecuteReader();
                DataList1.DataSource=rd;
                DataList1.DataBind(); 
                rd.Close();
                conn.Close();
            }        protected void BoundData(object sender,DataListItemEventArgs e)
            {
                if(e.Item.ItemType==ListItemType.Item||e.Item.ItemType==ListItemType.AlternatingItem)
                {
                    DataGrid dg=(DataGrid)e.Item.FindControl("DataGrid3");
                    TextBox txtClassid=(TextBox)e.Item.FindControl("txtBox");
                    string index=txtClassid.Text;
                    SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["SiteSqlServer"]);
                    SqlCommand comm=new SqlCommand("select top 10 a.PostID,a.Subject,b.ForumID,b.Name from forums_Posts as a left join forums_Forums as b on a.ForumID=b.ForumID where b.ForumGroupID="+index,conn);
                    conn.Open();
                    SqlDataReader rd=comm.ExecuteReader();
                    dg.DataSource=rd;
                    dg.DataBind(); 
                    rd.Close();
                    conn.Close();
                }   
            }
      

  3.   

    Datalist嵌套Datalist
    2009年03月28日 星期六 16:37
    <asp:datalist id="dlFileType" RepeatColumns="2" runat="server">
         <ItemTemplate>
             <table border="0" cellspacing="0" cellpadding="0">
                 <tr>
                     <td width="22%" height="88" align="center" valign="top">
                         <img src='<%#DataBinder.Eval(Container.DataItem, "cnvcPicURL")%>' width="80"   height="80">
                     </td>
                     <td valign="top">
                         <table width="96%" border="0" cellpadding="0" cellspacing="0">
                             <tr width="100%">
                                 <td colspan="2"><img src='<%#PageBase.strStyleRoot+"/picture/pic_fwzn_08.gif"%>' width="154" height="20">
                                     <asp:Label id="labFileType" runat="server" Visible=False Text='<%# DataBinder.Eval(Container.DataItem,"cniFileTypeID")%>'>
                                     </asp:Label></td>
                             </tr>
                             <tr>
                                 <td width="300">
                                     <asp:DataList id="dlFileList" runat="server" RepeatColumns="1" Width="100%">
                                         <ItemTemplate>
                                             <TABLE cellSpacing="1" cellPadding="1" width="100%" border="0">
                                                 <tr>
                                                     <td width="7%" height="20" align="center">
                                                         <img src='<%#PageBase.strStyleRoot+"/picture/pic_fwzn_dot.gif"%>' width="3" height="3"></td>
                                                     <td width="93%">
                                                         <font color="#393939">
                                                             <%#GetTitle((string)Convert.ToString(DataBinder.Eval(Container.DataItem, "cnvcTitle")),(string)Convert.ToString(DataBinder.Eval(Container.DataItem, "cnvcFileType")),(string)Convert.ToString(DataBinder.Eval(Container.DataItem, "cniBaseFileID")),(DateTime)DataBinder.Eval(Container.DataItem, "cndtPublishTime"))%>
                                                         </font>
                                                     </td>
                                                 </tr>
                                             </TABLE>
                                         </ItemTemplate>
                                     </asp:DataList>
                                 </td>
                             </tr>
                             <tr>
                                 <td colspan="2" bgcolor="E6E6E6" height="1"><img src='<%#PageBase.strStyleRoot+"/picture/1X1.gif"%>' width="1" ></td>
                             </tr>
                             <tr align="center">
                                 <td height="22" colspan="2"><a href="#" title="可查看到更多相关内容"><img src='<%#PageBase.strStyleRoot+"/picture/more.gif"%>' width="34" height="11" border="0"></a></td>
                             </tr>
                         </table>
                     </td>
                 </tr>
             </table>
         </ItemTemplate>
    </asp:datalist>
    .cs:private void dlFileType_ItemDataBound(object sender, System.Web.UI.WebControls.DataListItemEventArgs e)    
         {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) 
             
            {
                    DataList    dl = null;
                    Label    labTypeID = null;
                    
                    dl = (DataList)e.Item.FindControl("dlFileList")
                    labTypeID = (Label)e.Item.FindControl("lbFileType");                string typeID = labTypeID.Text.ToString();
                 int iTypeID = Convert.ToInt32(typeID);            string commandText = "select * from tbfile";
                commandText = commandText + " Where TypeID=" + iTypeID;
        
                string connString = ConfigurationSettings.AppSettings["dsn"];
                    SqlConnection conn = new SqlConnection();
                conn.ConnectionString = connString;
                conn.Open();
                SqlDataAdapter   myCommand = new SqlDataAdapter(commandText,conn);
                DataSet ds = new DataSet();
                myCommand .Fill(ds,"tbFile");
                conn.Close();    
                    dl.DataSource = ds.Tables["tbFile"];;
                    dl.DataBind();
               }
        }
      

  4.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    <html xmlns="http://www.w3.org/1999/xhtml" >  
    <head runat="server">  
        <title>DataListNesting</title>  
    </head>  
    <body>  
    <form id="form1" runat="server">  
    <div>  
    <asp:DataList ID="DataList1" runat="server">  
        <ItemTemplate>  
            <asp:Label ID="Label1" runat="server" Text='<%# Eval("OrderID") %>'></asp:Label>  
            <asp:Label ID="Label2" runat="server" Text='<%# Eval("CustomerID") %>'></asp:Label>  
            <asp:DataList ID="DataList2" runat="server" DataSource='<%# GetDetails(Eval("OrderID").ToString()) %>'>  
                <ItemTemplate>  
                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label>  
                    <asp:Label ID="Label2" runat="server" Text='<%# Eval("UnitPrice") %>'></asp:Label>  
                    <asp:Label ID="Label3" runat="server" Text='<%# Eval("Quantity") %>'></asp:Label>  
                </ItemTemplate>  
            </asp:DataList>  
        </ItemTemplate>  
    </asp:DataList>  
    </div>  
    </form>  
    </body>  
    </html>  private void BindList()   
        {   
            SqlConnection cn = new SqlConnection(@"server=.\sqlexpress;uid=sa;pwd=;database=northwind");   
            SqlDataAdapter da = new SqlDataAdapter("select OrderID, CustomerID from Orders", cn);   
            DataSet ds = new DataSet();   
            cn.Open();   
            da.Fill(ds);   
            cn.Close();   
            DataList1.DataSource = ds.Tables[0].DefaultView;   
            DataList1.DataKeyField = "orderID";   
            DataList1.DataBind();   
        }   
      
        protected DataTable GetDetails(string orderID)   
        {   
            SqlConnection cn = new SqlConnection(@"server=.\sqlexpress;uid=sa;pwd=;database=northwind;");   
            SqlDataAdapter da = new SqlDataAdapter("select ProductID, UnitPrice, Quantity from [Order Details] where orderID = @orderID", cn);   
            da.SelectCommand.Parameters.AddWithValue("@orderID", orderID);   
            DataSet ds = new DataSet();   
            cn.Open();   
            da.Fill(ds);   
            cn.Close();   
            return ds.Tables[0];   
        }   
      
        private void Page_Load(object sender, System.EventArgs e)   
        {   
            if (!IsPostBack)   
            {   
                BindList();   
            }   
        }