以下是我获取企业信息的一段代码//注 这个文件为*.CS里的代码
 
  public static void company_getcompanyinfo()
    {
        read =get_dataset("select * from company where accountid=" + states.session_Overtime(sll.split(Convert.ToString(HttpContext.Current.Session["account"]), 1)));
        if (read.Tables[0].Rows.Count > 0)
        {
            c_companyname.Text = read.Tables[0].Rows[0]["companyname"].ToString();
            c_contactperson.Text = read.Tables[0].Rows[0]["contactperson"].ToString();
            c_tel.Text = read.Tables[0].Rows[0]["tel"].ToString();
            c_fax.Text = read.Tables[0].Rows[0]["fax"].ToString();
            c_net.Text = read.Tables[0].Rows[0]["net"].ToString();
            c_email.Text = read.Tables[0].Rows[0]["email"].ToString();
            c_msn.Text = read.Tables[0].Rows[0]["msn"].ToString();
            c_qq.Text = read.Tables[0].Rows[0]["qq"].ToString();
            c_address.Text = read.Tables[0].Rows[0]["address"].ToString();
            c_postcode.Text = read.Tables[0].Rows[0]["postcode"].ToString();
        }
        else
        {
            prompt.alert_oflocation("提示:操作失败!可能原因为未查找到企业信息!", "iframe_ofindex.aspx");
        }
        read = null;
    }
    #endregion我有很多页面*.aspx.cs文件里想都调用这个函数,我都做company_getcompanyinfo()静态调用,但执行到这c_companyname.Text 提示我:CS0103: 当前上下文中不存在名称“c_companyname”.我也想做返回值,但函数只能返回一个返回值,我需要返回很多有很多地方都需要调用企业信息,都要调用这个代码,我还不想每个地方都写,只想写一个然后调用,请问该如何解决呢 ?(注:不使用自定义控件的方法),请问该如何解决()

解决方案 »

  1.   

    但函数只能返回一个返回值,我需要返回很多有很多地方都需要调用企业信息,都要调用这个代码
    ---------------
    返回企业类型的实例,字段封装的类型的属性中即可
    如:
    public static company company_getcompanyinfo()
      

  2.   

    yan63(silence like a cancer grows) ( ) 信誉:100  2007-08-03 14:39:37  得分: 0  
     
     
       但函数只能返回一个返回值,我需要返回很多有很多地方都需要调用企业信息,都要调用这个代码
    ---------------
    返回企业类型的实例,字段封装的类型的属性中即可
    如:
    public static company company_getcompanyinfo()
      
     楼上兄弟。哎  一工就那点代码 你全了
      

  3.   

    返回一个datatable罗,要不返回List<company>
      

  4.   

    你完全可以用一个公司的model 来承载这些信息,就是说先定义一个公司信息的实体对象,包含你所需要的所有信息,即属性,到时候通过实体对象作为返回值来传递就OK了
      

  5.   

    c_companyname.Text不是每个页面都有!再说了,象你那种写法只能在一个页面中被调用!也想做返回值,但函数只能返回一个返回值,我需要返回很多
    ---------------------------------------------------------
    你可以将company_getcompanyinfo()写成只返回dataset或datatable等。然后再将数据源绑定到控件上。
      

  6.   

    1。有返回值就不能用void 
    2。c_companyname.Text没有,要先定义
    public static company_getcompanyinfo(TextBox c_companyname,TextBoxc_contactperson,....(几个几个类似参数全部写上))
    {
    read =get_dataset("select * from company where accountid=" + states.session_Overtime(sll.split(Convert.ToString(HttpContext.Current.Session["account"]), 1)));
    if (read.Tables[0].Rows.Count > 0)
    {
    c_companyname.Text = read.Tables[0].Rows[0]["companyname"].ToString();
    c_contactperson.Text = read.Tables[0].Rows[0]["contactperson"].ToString();
    c_tel.Text = read.Tables[0].Rows[0]["tel"].ToString();
    c_fax.Text = read.Tables[0].Rows[0]["fax"].ToString();
    c_net.Text = read.Tables[0].Rows[0]["net"].ToString();
    c_email.Text = read.Tables[0].Rows[0]["email"].ToString();
    c_msn.Text = read.Tables[0].Rows[0]["msn"].ToString();
    c_qq.Text = read.Tables[0].Rows[0]["qq"].ToString();
    c_address.Text = read.Tables[0].Rows[0]["address"].ToString();
    c_postcode.Text = read.Tables[0].Rows[0]["postcode"].ToString();
    }
    else
    {
    prompt.alert_oflocation("提示:操作失败!可能原因为未查找到企业信息!", "iframe_ofindex.aspx");
    }
    read = null;
    }
    #endregion
      

  7.   

    1\可以使用实体类
    2\返回dataset或datatable,个人觉得不太合适.
    3\使用引用传递,即byref
    4\不嫌麻烦的话还可以写载重