CS页面中定义一个 public比如前台是<%=i%>CS 中就是 public int i 这样i就能在前台显示了

解决方案 »

  1.   

    后台
    public int i = 10;//必须是public
    在pageload里执行
    {
    this.Page.DataBind()
    }前台就<%#i%>
      

  2.   

    前台:
    <table>
    <tr><td id="mytd" runat="server"></td></tr></table>
    后台:
    public class 页面名 : PageBase
    {
      protected System.Web.UI.HtmlControls.HtmlTableCell mytd;
        ...
        private void Page_Load(object sender, System.EventArgs e)
        {
            string ss;
            ss = "<table>";
            for(int i=0;i<20;i++)
            {
                ss += "<tr>"+i.ToString()+"</tr>";
            }
            ss += "</table";
            this.mytd.InnerHtml = ss;
        }
        ...
    }
      

  3.   

    在前台访问的应该是Public型的变量,
      

  4.   

    在这种情况下用protected就可以了
      

  5.   

    不一定要public,protected变量就可以了
      

  6.   

    我可能没说清楚,上面只是举个例子
    我把代码稍微贴一下:
    .aspx 中:<%  int j;
    for(j=1;j<=daysInMonth;j++) {  %>  
       <td bgcolor="#FFFFFF">
    <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
    <td colspan="2" align="center" bgcolor="#E8EEF7" style="height: 19px" >
      <<%=j%>
    </td>
    </tr>
    <tr>
    <td valign="top" style=" height: 20px">
    <asp:DataList ID="ShowMonthList" runat="server" >
    <ItemTemplate>
    <tr><td>
    <%# DataBinder.Eval(Container.DataItem,"releaseTime")%>
     </td>
    <td><%# DataBinder.Eval(Container.DataItem,"contents") %></td>
    </tr>
    </ItemTemplate>
     </asp:DataList>
    </td>
    </tr>
    </table>
    </td>
    <%} %> 
    我这里的j是日历中的每一天,我想根据这个天数查询数据库的记录
      

  7.   

    不明白lz的意思了,,这种事情非要在前台这样写代码?后台不能写么?后台没有Table服务器控件?
      

  8.   

    在cs文件里做循环 把需要的参数传到cs文件里 在里面处理 
    把所有需要的标记放到字符串里面
    string show;
    for(j=1;j<=daysInMonth;j++) 
    {
    show=“   <td bgcolor="#FFFFFF"> <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">”
    show+=“<tr><td colspan="2" align="center" bgcolor="#E8EEF7" style="height: 19px" >
      <<%=j%>”
    ……
    show+=“<td valign="top" style=" height: 20px">”+取到的数据+“</td>”
    ……
    }
    最后把这个字符串打出来就ok了
    可以用 response.write(show)在页面上;或则在要显示的地方 放个label在处理完数据后直接把label.text=show 也可以
      

  9.   

    还有没有别的建议在后台写table呢
      

  10.   

    table tb = new table();
    tablecolumn td = new tablecolumn();
    tablerow tr = new tablerow():textbox txt = new textbox();
    txt.text = "hahaha";td.controls.add(txt)
    tr.controls.add(td);
    tb.controls.add(tr);_________________________
    大概这样子
      

  11.   

    定义style: tb.Style.Add("width","100%")占位可用PlaceHolder控件
      

  12.   

    无法获得,因为<% %>在Init阶段就做了,相当于Init调用的一个私有函数的内部变量。
      

  13.   

    其实如大家所说,可以在后台.cs里面先定义变量J,进行循环后,输出或是动态定义表,这样就知道循环变量的值了,是设计思路的问题
      

  14.   

    在CS页定义Public 变量
      

  15.   

    this.RegisterStartupScript("test", "<script language=javascript> document.all(\"text5\").value = " + t + " </script>");