不知道为什么,我在使用datalist显示数据库的纪录的时候总是隔一条显示一条?

解决方案 »

  1.   

    你是不是用datareader绑定数据的,用dataset做数据源试一试
      

  2.   

    html如下:
    <asp:datalist id="score" runat="server" Width="700" Height="80px">
    <HeaderTemplate>
    <font face="宋体">
    <table width="700" border="0">
    <tr>
    <td width="191">产品图片</td>
    <td width="254">标题/公司信息</td>
    <td width="301">诚信会员</td>
    </tr>
    </table>
    </font>
    </HeaderTemplate>
    <EditItemStyle BackColor="Yellow"></EditItemStyle>
    <SelectedItemTemplate>
    <FONT face="宋体"></FONT>
    </SelectedItemTemplate>
    <AlternatingItemStyle BackColor="Gainsboro"></AlternatingItemStyle>
    <FooterTemplate>
    <font face="宋体"></font>
    </FooterTemplate>
    <ItemTemplate>
    <TABLE width="700" border="0">
    <TR>
    <TD width="191" rowSpan="3"><FONT face="宋体"></FONT><FONT face="宋体"></FONT><FONT face="宋体"></FONT><FONT face="宋体"></FONT><FONT face="宋体"></FONT><FONT face="宋体"></FONT><FONT face="宋体"></FONT><FONT face="宋体"></FONT><A href='TradeDetail.aspx?id=<%# DataBinder.Eval(Container.DataItem,"id").ToString() %>' target=_blank><%# DataBinder.Eval(Container.DataItem,"name") %></A></TD>
    <TD width="254">公司负责人<%# DataBinder.Eval(Container.DataItem,"f_name") %></TD>
    <TD width="301" rowSpan="3"><%# DataBinder.Eval(Container.DataItem,"gs_name") %><FONT face="宋体"></FONT></TD>
    </TR>
    <TR>
    <TD><%# DataBinder.Eval(Container.DataItem,"gs_name") %><FONT face="宋体"></FONT></TD>
    </TR>
    <TR>
    <TD>发布时间<%# DataBinder.Eval(Container.DataItem,"fbtime") %></TD>
    </TR>
    </TABLE>
    </ItemTemplate>
    <HeaderStyle BackColor="#AAAADD"></HeaderStyle>
    <AlternatingItemTemplate>
    <FONT face="宋体"></FONT>
    </AlternatingItemTemplate>
    </asp:datalist>
    cs文件如下:
    ICollection CreateSource()  
    {  int StartIndex;  
    string type_d=Request.QueryString["type_d"].ToString();
    //设定导入的起终地址  
    StartIndex = CurrentPage*PageSize;  
    string strSel = "select cp.id,cp.gongsi_id,cp.gs_name,cp.name,cp.fbtime,users.f_name from cp left join users on cp.gongsi_id=users.pkid";// where hylb_d= '"+type_d+"'"; 
    SqlConnection sqlConnection=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["msdsn"]);
    DataSet ds = new DataSet();  
    SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,sqlConnection);  
    MyAdapter.Fill(ds,StartIndex,PageSize,"cp");  
    return ds.Tables["cp"].DefaultView;  
    }
      

  3.   

    <AlternatingItemTemplate>
    <FONT face="宋体"></FONT>
    </AlternatingItemTemplate>
    去掉
      

  4.   

    to: LoveCherry(最讨厌你们这些要代码的了,一点技术含量都没有)<AlternatingItemTemplate>
    <FONT face="宋体"></FONT>
    </AlternatingItemTemplate>
    请教,这个是什么意思?(我是从其他地方直接考过来的代码,所以不知道是什么)
      

  5.   

    <AlternatingItemTemplate>
    <FONT face="宋体"></FONT>
    </AlternatingItemTemplate>
    请教,这个是什么意思?(我是从其他地方直接考过来的代码,所以不知道是什么)
    -----------------------------------------------------------------------------〉
    交替行的意思:即2468...行
      

  6.   

    也就是交替显示的意思
    你可以测试一下,把数据也邦定到
    <AlternatingItemTemplate>
    <FONT face="宋体"></FONT>
    </AlternatingItemTemplate>
    里面,并且设置成不同的样式
    就会显示
    1
    2
    3
    4
    5
    6这样,1,3,5的样式是相同的,2,4,6是另一种样式
      

  7.   

    to: LoveCherry(最讨厌你们这些要代码的了,一点技术含量都没有)
    to: noyester(继续是菜鸟)
    to: AllenTing(我爱吃醋)谢谢!