用可以使用out参数来把这三个值传出:
public static string  showstate(string Views_mysql,out string lblallcount,out string lblpagecount,out string lblcurrentindex, DataGrid member_gr)
    {
        lblallcount = null;
        lblpagecount = null;
        lblcurrentindex = null;       SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["Str_sql"]);
        cn.Open();
        SqlDataAdapter da = new SqlDataAdapter(Views_mysql,cn);
        DataSet ds = new DataSet();
        da.Fill(ds,"member_page");
        DataTable dt = ds.Tables["member_page"];
        int count = dt.Rows.Count;
        lblallcount = count.ToString();//获取总记录
        lblpagecount = member_gr.PageCount.ToString();//获取总页数
        lblcurrentindex = Convert.ToString(member_gr.CurrentPageIndex + 1);    }

解决方案 »

  1.   

    pubcli aaa;
    public static string  showstate(string Views_mysql,string lblallcount,string lblpagecount,string lblcurrentindex, DataGrid member_gr)
        {       SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["Str_sql"]);
            cn.Open();
            SqlDataAdapter da = new SqlDataAdapter(Views_mysql,cn);
            DataSet ds = new DataSet();
            da.Fill(ds,"member_page");
            DataTable dt = ds.Tables["member_page"];
            int count = dt.Rows.Count;
            lblallcount = count.ToString();//获取总记录
            lblpagecount = member_gr.PageCount.ToString();//获取总页数
            lblcurrentindex = Convert.ToString(member_gr.CurrentPageIndex + 1);
           aa=dt.Rows.Count;
        }在页面调用。xxx.aa
      

  2.   

    定义三个public属性,分别得到他们的值。
    在任何地方都可以调用了
      

  3.   

    在使用上你可以这样:string str1;
    string str2;
    string str3;
    this.showstate("aa",out str1,out str2,out str3, dg);Console.WriteLine(str1);
    Console.WriteLine(str2);
    Console.WriteLine(str3);
      

  4.   

    public static string  showstate(string Views_mysql,ref  string  lblallcount,ref string lblpagecount,ref string lblcurrentindex, DataGrid member_gr)
    用ref
      

  5.   

    给你个例子。。
    http://hi.baidu.com/kmiaoer/blog/item/40be064fa4cbc337aec3ab7c.html
      

  6.   

    public string aaa;
    纠正一下。。呵呵~~~~
      

  7.   

    out  或者 全局 或者定义一个对象、结构
      

  8.   

    我按照这位仁兄 hbxtlhx(平民百姓) 的做做出现如下错误
    编译器错误信息: CS0161: “Member_all.showstate(string, out string, out string, out string, System.Web.UI.WebControls.DataGrid)”: 并非所有的代码路径都返回值 public static string showstate(string Views_mysql, out string lblallcount, out string lblpagecount, out string lblcurrentindex, DataGrid member_gr)
    行 1135:
      

  9.   

    我调用的时候        Member_all.showstate(Convert.ToString(ViewState["mysql"]),lblallcount.Text,lblpagecount.Text,lblcurrentindex.Text,member_Gr);
    这样写的,不知道对不对
      

  10.   

    out参数是引用参数,参数的值能随方法里面做的改变而改变,但无需预先赋值
    还有中ref参数也是引用参数,跟out的区别是需要预先赋值
      

  11.   

    public static void showstate(string Views_mysql,out string lblallcount,out string lblpagecount,out string lblcurrentindex, DataGrid member_gr)
      

  12.   

    按上边仁兄的做法shaohaiou() ( ) 信誉:100    Blog   加为好友 
    出现了
    编译器错误信息: CS1502: 与“Member_all.showstate(string, out string, out string, out string, System.Web.UI.WebControls.DataGrid)”最匹配的重载方法具有一些无效参数
      

  13.   

    hbxtlhx(平民百姓) ( ) 信誉:112    哟
      

  14.   

    Member_all.showstate(Convert.ToString(ViewState["mysql"]),lblallcount.Text,lblpagecount.Text,lblcurrentindex.Text,member_Gr);
    这是调用的时候
      

  15.   

    Member_all.showstate(Convert.ToString(ViewState["mysql"]),out lblallcount.Text,out lblpagecount.Text,out lblcurrentindex.Text,member_Gr);
      

  16.   

    nhtoby(飞不起的翼) ( ) 信誉:100    Blog   加为好友  2007-04-29 15:30:15  得分: 0  
     
     
       返回一个数组应该可以
      
     
    ---------------------------------
    就没人看见么,非得写的像其他人那么麻烦么?
    public static string[]  showstate(string Views_mysql,string lblallcount,string lblpagecount,string lblcurrentindex, DataGrid member_gr)
        {
           string[] temp=new string[3];
           SqlConnection cn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["Str_sql"]);
            cn.Open();
            SqlDataAdapter da = new SqlDataAdapter(Views_mysql,cn);
            DataSet ds = new DataSet();
            da.Fill(ds,"member_page");
            DataTable dt = ds.Tables["member_page"];
            int count = dt.Rows.Count;
            lblallcount = count.ToString();//获取总记录
            lblpagecount = member_gr.PageCount.ToString();//获取总页数
            lblcurrentindex = Convert.ToString(member_gr.CurrentPageIndex + 1);
            temp[0]=lblallcount ;
            temp[1]=lblpagecount ;
            temp[2]=lblpagecount ;
            return temp;
        }
      

  17.   

    这是啥意思属性或索引器不得作为 out 或 ref 参数传递
      

  18.   

    lblallcount.Text 之类的 都用变量代替
      

  19.   

    返回多值可以的方案有:
    1 传入引用
    2 传入指针
    3 返回类型(类/struct/类似概念)
      

  20.   

    我按楼上这位:shaohaiou()
    string lblallcount1 = lblallcount.Text;
            string lblpagecount1 =lblpagecount.Text;
            string lblcurrentindex1 = lblcurrentindex.Text;        Response.Write(lblallcount1);
            Member_all.showstate(Convert.ToString(ViewState["mysql"]), out lblallcount1, out lblpagecount1, out lblcurrentindex1, member_Gr);不知道为什么得到的lblallcount1,lblpagecount1,等全是lable
      

  21.   

    为什么你要再传入之前赋值
    如果要赋值可以用ref不用out