<asp:datalist id="DataList1" DataKeyField="productid" RepeatColumns='5' runat="server" RepeatDirection="Horizontal" CellSpacing="1" CellPadding="3">我用数据<%= dr["repeatcoumnkkkk"].ToString()%>控制RepeatColumns或者其他显示提示编译器错误...非int32格式..请问怎样做才能控制前台datalist显示的横纵列数??

解决方案 »

  1.   

    RepeatColumns='5' 
    RepeatDirection="Horizontal"
      

  2.   

    搂主可以使用RepeatColumns属性设置重复列..另外不要在页面上使用dr["dd"]这样的代码..将数据源绑定到控件中..
      

  3.   

    SDK里的例子:
    RepeatDirection="Horizontal"
    RepeatDirection="Vertical"---------------------------------------
    <%@ Page Language="C#" AutoEventWireup="True" %>
    <%@ Import Namespace="System.Data" %>
     
    <html>
       <script runat="server">
     
          ICollection CreateDataSource() 
          {
          
             // Create sample data for the DataList control.
             DataTable dt = new DataTable();
             DataRow dr;
     
             // Define the columns of the table.
             dt.Columns.Add(new DataColumn("IntegerValue", typeof(Int32)));
             dt.Columns.Add(new DataColumn("StringValue", typeof(String)));
             dt.Columns.Add(new DataColumn("CurrencyValue", typeof(double)));
             dt.Columns.Add(new DataColumn("ImageValue", typeof(String)));
     
             // Populate the table with sample values.
             for (int i = 0; i < 9; i++) 
             {
                dr = dt.NewRow();
     
                dr[0] = i;
                dr[1] = "Description for item " + i.ToString();
                dr[2] = 1.23 * (i + 1);
                dr[3] = "Image" + i.ToString() + ".jpg";
     
                dt.Rows.Add(dr);
             }
     
             DataView dv = new DataView(dt);
             return dv;
          }
     
     
          void Page_Load(Object sender, EventArgs e) 
          {         // Load sample data only once, when the page is first loaded.
             if (!IsPostBack) 
             {
                ItemsList.DataSource = CreateDataSource();
                ItemsList.DataBind();
             }      }
     
          void Button_Click(Object sender, EventArgs e) 
          {
     
             // Set the repeat direction based on the selected value of the
             // DirectionList DropDownList control.
             ItemsList.RepeatDirection = 
                 (RepeatDirection)DirectionList.SelectedIndex;         // Set the repeat layout based on the selected value of the
             // LayoutList DropDownList control.
             ItemsList.RepeatLayout = (RepeatLayout)LayoutList.SelectedIndex;         // Set the number of columns to display based on the selected
             // value of the ColumnsList DropDownList control.
             ItemsList.RepeatColumns = ColumnsList.SelectedIndex;         // Show or hide the gridlines based on the value of the
             // ShowBorderCheckBox property. Note that gridlines are displayed
             // only if the RepeatLayout property is set to Table.
             if ((ShowBorderCheckBox.Checked) 
                 && (ItemsList.RepeatLayout == RepeatLayout.Table)) 
             {
                ItemsList.BorderWidth = Unit.Pixel(1);
                ItemsList.GridLines = GridLines.Both;
             }    
             else  
             {
                ItemsList.BorderWidth = Unit.Pixel(0);
                ItemsList.GridLines = GridLines.None;
             }
        
          }    
     
       </script>
     
    <body>
     
       <form runat=server>      <h3>DataList Example</h3>
     
          <asp:DataList id="ItemsList"
               BorderColor="black"
               CellPadding="5"
               CellSpacing="5"
               RepeatDirection="Vertical"
               RepeatLayout="Table"
               RepeatColumns="0"
               ShowBorder="False"
               runat="server">         <HeaderStyle BackColor="#aaaadd">
             </HeaderStyle>         <AlternatingItemStyle BackColor="Gainsboro">
             </AlternatingItemStyle>         <HeaderTemplate>            List of items         </HeaderTemplate>
                   
             <ItemTemplate>            Description: <br>
                <%# DataBinder.Eval(Container.DataItem, "StringValue") %>            <br>            Price: <%# DataBinder.Eval(Container.DataItem, "CurrencyValue", "{0:c}") %>            <br>            <asp:Image id="ProductImage"
                     ImageUrl='<%# DataBinder.Eval(Container.DataItem, "ImageValue") %>'
                     runat="server"/>         </ItemTemplate>
     
          </asp:DataList>
     
          <hr>      <table cellpadding="5">         <tr>            <td>               Repeat direction:            <td>            <td>               Repeat layout:            <td>            <td>               Repeat columns:            <td>            <td>               <asp:CheckBox id="ShowBorderCheckBox"
                        Text="Show border"
                        Checked="False" 
                        runat="server" />            <td>         </tr>         <tr>            <td>               <asp:DropDownList id="DirectionList" 
                        runat="server">                  <asp:ListItem>Horizontal</asp:ListItem>
                      <asp:ListItem Selected="True">Vertical</asp:ListItem>               </asp:DropDownList>            <td>            <td>               <asp:DropDownList id="LayoutList" 
                        runat="server">                  <asp:ListItem Selected="True">Table</asp:ListItem>
                      <asp:ListItem>Flow</asp:ListItem>               </asp:DropDownList>            <td>            <td>               <asp:DropDownList id="ColumnsList" 
                        runat="server">                  <asp:ListItem Selected="True">0</asp:ListItem>
                      <asp:ListItem>1</asp:ListItem>
                      <asp:ListItem>2</asp:ListItem>
                      <asp:ListItem>3</asp:ListItem>
                      <asp:ListItem>4</asp:ListItem>
                      <asp:ListItem>5</asp:ListItem>               </asp:DropDownList>            <td>            <td>               &nbsp;            <td>
             </tr>      </table>     
             
          <asp:LinkButton id="RefreshButton" 
               Text="Refresh DataList" 
               OnClick="Button_Click" 
               runat="server"/>
     
       </form>
     
    </body>
    </html>
      

  4.   

    <asp:datalist id="DataList1" DataKeyField="productid" RepeatColumns='<%= dr["repeatcoumnkkkk"].ToString()%>' runat="server" RepeatDirection="Horizontal" CellSpacing="1" CellPadding="3">
    显示错误的????
    我的意思是说怎样在网站管理后台控制前台首页index.aspx中的datalist显示????就是说我后台有几个文本框
    有:
    显示行数:
    显示列数:
    行间隔:
    我输入点确定,数据更新到数据库,前台就更新了~~~~我说的是这样!
    而不是说怎么显示datalist行数,,这个我会.....