例如我要生成一个课程表
--------------------
时间 | 教室 | 课程 |
--------------------
上午 | ×× | ×× |
--------------------
上午 | ×× | ×× |
--------------------
下午 | ×× | ×× |
--------------------
下午 | ×× | ×× |
--------------------现在想把时间相同的单元格合并,就是
--------------------
时间 | 教室 | 课程 |
--------------------
   | ×× | ×× |
上午 |--------------
   | ×× | ×× |
--------------------
   | ×× | ×× |
下午 |--------------
   | ×× | ×× |
--------------------用datalist如何绑定呢,新手上路,请多多指教,3x

解决方案 »

  1.   

    再搭问一个,如何在绑定的条目中添加一些东西,比如新闻1
    新闻2 (hot)
    新闻3新闻1到3是直接从数据库里读取的,另外再读一个变量例如是hits
    当这个值大于某个数时,就显示后面的那个(hot)我用的C#,谢谢
      

  2.   

    to: wxqq2001
    我是新手,在书上的例子里,只看到有那种绑定一个datasource
    直接生成一个方方正正的表稍微有点变动,就象上面说的,我就不知道怎么生成了有没有直接画表格的例子给一个看看,谢谢了
      

  3.   

    楼主可以把你的代码贴上来看看么?前台.具体哪些地方需要绑定数据呢?我的意思是能直接用html生成的地方尽量不要用程序写.
      

  4.   

    绑定数据要修改的话可以这样:
    private void DataBind()
    {
    DataTable dt=// 数据源 this.DataList1.DataSource=dt;
    this.DataList1.DataBind();
    for(int i=0;i<this.DataList1.Items.Count;i++)
    {
    Label label=(Label)this.DataList1.Items[i].FindControl("typeidLbl");
    string typeid=label.Text;
    //这里可以用FindControl的方法做你想做的任何事情. }
    }
      

  5.   

    我是在书上看的例子,是这样的
    aspx页面内:
    <asp:DataList id="myDataList" runat="server">
    <table width="300" border="1">
    <ItemTemplate>
    <tr>
    <td> <%# ((System.Data.Common.DbDataRecord)Container.DataItem)["时间"] %> </td>
    <td> <%# ((System.Data.Common.DbDataRecord)Container.DataItem)["教室"] %> </td>
    <td> <%# ((System.Data.Common.DbDataRecord)Container.DataItem)["课程"] %> </td>
    </tr>
    </TtemTemplate>
    </table>
    </asp:DataList>--------------------
    cs页面内private void Page_Load(object sender, System.EventArgs e)
    {
    SqlConnection myConn=new SqlConnection("........");
    SqlCommand myCommand= new SqlCommand("select .....",myConn);
    myConn.Open(); sqlDataReader dr=myCommand.ExecuteReader();
    myDataList.DataSource=dr;
    myDataList.DataBind();
    }如何直接用html生成呢
      

  6.   

    直接在dataList中嵌套个表格,再按着表格的方式来处理就ok了,
    并不复杂
      

  7.   

    直接用 Table datalist 一般用在有规律的显示
      

  8.   

    就以上面那个课程表的例子来说
    如何直接用Table写呢
    把"时间"字段相同的单元格合并到一起还是用以前的response.write 来手动输出吗?
      

  9.   

    datalist好象是不容易实现合并单元格。用datagrid可以,在ItemDataBind事件中判断是否相同,是的话直接Remove,并增加未移除的单元格的Rowspan属性即可
      

  10.   

    SpbDev(急先锋) 的方法好象是可以用的请问直接写HTML的方法是怎么做的呢
      

  11.   

    你的难处是在设计这个表格,
    有了这个表格,填充数据该是容易的吧
    <TABLE id="Table5" style="Z-INDEX: 103; LEFT: 56px; POSITION: absolute; TOP: 176px" cellSpacing="1"
    cellPadding="1" width="300" border="1">
    <TR>
    <TD width="200">时间</TD>
    <TD width="200">教室</TD>
    <TD width="200">课程</TD>
    </TR>
    <TR>
    <TD colSpan="3">
    <TABLE id="Table6" cellSpacing="0" cellPadding="0" border="0" width="100%" height="100%">
    <TR>
    <TD width="200">上午</TD>
    <TD width="400">
    <TABLE id="Table7" height="100%" cellSpacing="0" cellPadding="0" border="0" width="100%">
    <TR>
    <TD></TD>
    <TD></TD>
    </TR>
    <TR>
    <TD></TD>
    <TD></TD>
    </TR>
    <TR>
    <TD></TD>
    <TD></TD>
    </TR>
    </TABLE>
    </TD>
    </TR>
    <TR>
    <TD>下午</TD>
    <TD width="200"><FONT face="宋体">
    <TABLE id="Table8" height="100%" width="100%" cellSpacing="0" cellPadding="0" border="0">
    <TR>
    <TD><FONT face="宋体"></FONT></TD>
    <TD></TD>
    </TR>
    <TR>
    <TD></TD>
    <TD></TD>
    </TR>
    <TR>
    <TD></TD>
    <TD></TD>
    </TR>
    </TABLE>
    </FONT>
    </TD>
    </TR>
    </TABLE>
    </FONT>
    </TD>
    </TR>
    </TABLE>
      

  12.   

    我也碰到这种问题 不过更复杂 你可以用Table控件 然后动态对这个控件进行添加行和列 代码示例如下:
    public void com_list()
    {
                report.myData mydata1=new report.myData();
    DateTime dt1=Convert.ToDateTime(Date1.Text);
    DateTime dt2=Convert.ToDateTime(Date2.Text);
      mydata1.OpenConn();
    int i=1;
    while(dt1<=dt2)
    {//添加行
    TableRow r = new TableRow();
    r.HorizontalAlign=HorizontalAlign.Center;
    if(i%2==0)
    {
    r.BackColor=Color.LightGray;
    }
    i=i+1;
    //添加第一列
    TableCell c = new TableCell();
    c.Text = dt1.ToShortDateString();
    c.Width=90;
    c.Wrap=false;
    r.Cells.Add(c);
    //添加其它列
    string SQL="select name from workingplace where wastebookno not in(select wastebookno from dayreport where reportdate='"+dt1+"' and state<>0) and wastebookno<>''";
    SqlDataReader reader=mydata1.executeQuery(SQL);
    while(reader.Read())
    {
    TableCell c1 = new TableCell();
    c1.HorizontalAlign=HorizontalAlign.Center;
    c1.Text = reader["name"].ToString();
    r.Cells.Add(c1);
    }
        Table2.Rows.Add(r);
    dt1=dt1.AddDays(1);
    reader.Close();
    }
    Table5.Visible=true;
    Table3.Visible=false;
               Table2.Visible=true;
               mydata1.closeConn();
    }
      

  13.   

    这是更复杂的一个表:
    public void date_list()
    {
    report.myData mydata1=new report.myData();
    DateTime dt1=Convert.ToDateTime(Date1.Text);
    DateTime dt2=Convert.ToDateTime(Date2.Text);
    DateTime dt;
    TimeSpan daysSpan =dt2 - dt1;
    int days = Convert.ToInt32(daysSpan.Days.ToString());//获得间隔的天数 mydata1.OpenConn();
    string SQL="Select Name,WasteBookNo From WorkingPlace";
    DTable1=mydata1.FillDataTable(SQL);

     for(int i=0;i<DTable1.Rows.Count;i++) 

    string WBN=DTable1.Rows[i]["WasteBookNo"].ToString();
    string CName=DTable1.Rows[i]["name"].ToString();
    //查询这个店铺提交报表的天数
     /* string sql1="select Distinct Count(ReportDate) as cnt from DayReport where state<>0 and WasteBookNo='"+WBN+"' and ReportDate between '"+dt1+"' and '"+dt2+"'";
     SqlDataReader myReader1=mydata1.executeQuery(sql1);
     int cnt1;
     if(myReader1.Read())
     {
     cnt1=(int)myReader1.GetValue(0);
     }
     else{cnt1=0;} */
      int cnt1 =mydata1.ReportDays(WBN,dt1,dt2);
                     //myReader1.Close();
     if(cnt1<days+1)//如果提交的天数小于应有的天数,那么就列出未提交的日期
     {
     TableRow r = new TableRow();
     r.HorizontalAlign=HorizontalAlign.Center;
     //添加第一列
     TableCell c = new TableCell();
     c.Text = CName;
     c.Width=90;
     c.Wrap=false;
     r.Cells.Add(c);
     dt=dt1;
     //添加其它列
     while(dt<=dt2)
     {//判断该日期的报表提交没有,如果没有则显示日期
    /* string sql2="select Count(ReportDate) as cnt from DayReport where state<>0 and WasteBookNo='"+WBN+"' and ReportDate='"+dt+"'";
     SqlDataReader myReader2=mydata1.executeQuery(sql2);
     int cnt2;
     if(myReader2.Read())
     {
     cnt2=(int)myReader2.GetValue(0);
     }
     else{cnt2=0;}
     myReader2.Close(); */
     int cnt2 =mydata1.ReportNOT(WBN,dt);
     if(cnt2==0)
     {
     TableCell c1 = new TableCell();
     c1.HorizontalAlign=HorizontalAlign.Center;
     c1.Text = dt.ToShortDateString();
     r.Cells.Add(c1);
     }
     dt=dt.AddDays(1);
     }
     Table2.Rows.Add(r);
     }
    }
    Table3.Visible=true;
    Table5.Visible=false;
    Table2.Visible=true;
    mydata1.closeConn();
    }