asp.net 里没有过程概念。
用方法。

解决方案 »

  1.   

    <%@Import Namespace="System.Data"%>
    <%@Import Namespace="System.Data.SqlClient"%>
     <script language="C#" runat="server">function string LeftNews(int newsid,string types)  //这行错了
    {
     string html="";
     
     SqlDataReader dr=null;
     //如果是第4条记录,则显示更多内容
     int i=1;
    SqlConnection conn=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
     conn.Open(); 
     
    SqlCommand Cmd = new SqlCommand( "select top 4 id,subject from changnews where newsid='"+newsid+"'  And ischeck=1 order by id desc", conn);
            dr = Cmd.ExecuteReader();
          
    html+="<table width=100% border=0 align=center cellpadding=0 cellspacing=0>";
    html+="<tr><td height=22>&nbsp;&nbsp;&nbsp;<a href=/News/Show.aspx?types="+types+"  target=_blank><strong><font color=#009DDB>"+types+"</font></strong></a></td></tr>";

       while(dr.Read()==true)
       {
       //检查输出的标题是否太长
       string subjectA="",subject="";
        subject=dr["subject"].ToString();
    subject=subject.Trim();   if  (subject.Length>8)
       {
       subjectA=subject.Substring(0,8);
       }
       else
       {
       subjectA=subject;
       }
       if (i!=4)
       {
       html+="<tr><td height=22>&nbsp;&nbsp;&nbsp;<img src=images/point2.gif width=4 height=5>&nbsp;";
       html+="<a href=/news/shownews.aspx?id="+dr["id"]+"&types="+types+" target=_blank><font color=ffffff>"+subjectA+"</font></a></td></tr>";
       }
       else
       {
       html+="<tr><td height=22>&nbsp;&nbsp;&nbsp;<img src=images/point2.gif width=4 height=5>&nbsp;";
       html+="<a href=/news/shownews.aspx?id="+dr["id"]+"&types="+types+" target=_blank><font color=ffffff>"+subjectA+"</font></a>&nbsp;";
       html+="<a href=/news/show.aspx?types="+types+" target=_blank><font color=ffffff>更多&gt;&gt;</font></a></td></tr>";    
       }
       i=i+1;
       }
       html+="</table>";
       return html;
    dr.Close();
    conn.Close();
    }
    </script>
    <table>
    <tr> 
              <td height="22"><%Label1.Text=LeftNews(23,"精英论坛");%>  </td>
            </tr></table>
      

  2.   

    function string LeftNews(int newsid,string types) 改为:protected string LeftNews(int newsid,string types)