日期:2014-05-18  浏览次数:20491 次

我应该如何使用findcotrol来找到Label1控件,
我用Datalist控件,来呈现新闻列表,想在后面显示时间(5/17),在后定义了一个Label控件,运行后提示当前下文中没有Label1

前台代码:

    <asp:DataList   ID= "dlSZ "   runat= "server "   >
       
            <ItemTemplate>
           
            <table   class= "txt "   >
            <tr> <td   style= "width:1px; "> </td>     <td   style= "width:300px ">
                ·&nbsp;&nbsp;&nbsp;   <asp:LinkButton   ID= "LinkButton1 "     ForeColor= "#006666 "   runat= "server "   CommandName= "select "   > <%#   DataBinder.Eval(Container.DataItem, "title ")   %>   </asp:LinkButton>
                  </td>
            <td   style= "width:6px ">


      <asp:Label   ID= "Label1 "   runat= "server "   Text= "Label1 "> </asp:Label>  


            </td> </tr>
            </table>
            </ItemTemplate>  
            <HeaderStyle   HorizontalAlign= "Center "   />
                <AlternatingItemStyle   Font-Bold= "False "   />
              </asp:DataList>  

后台代码:

    public   partial   class   _Default   :   System.Web.UI.Page  
{
       

        BaseClass   bc   =   new   BaseClass();
        protected   void   Page_Load(object   sender,   EventArgs   e)
        {
     
                dlSZ.DataSource   =   bc.GetDataSet( "SELECT   TOP   10   *   FROM   xinwen   WHERE   (Type   =   '国内新闻 ') ",   "xinwen ");
                dlSZ.DataKeyField   =   "id ";
                dlSZ.DataBind();

                DataList1.DataSource   =   bc.GetDataSet( "SELECT   TOP   5   *   FROM   tbtu   order   by   addDate   desc ",   "tbtu ");
                DataList1.DataKeyField   =   "id ";
                DataList1.DataBind();

                DataList2.DataSource   =   bc.GetDataSet( "   SELECT   TOP   5   *   FROM   article   order   by   IssueDate   desc   ", "article ");