C# 在同一类的另一个方法中使用一个方法
我在同一个类中有两个方法,想了解如何在第二个方法中使用第一个方法。
// 第一种方法
public static void RefreshGridView(GridView GridView1)
{
GridView1.DataBind();
}
// 第二种方法
public static void AssignDefaultUserNameLetter(Literal categoryID, ObjectDataSource ObjectDataSource1)
{
// declare variable for filter query string
string userFirstLetter = HttpContext.Current.Request.QueryString["az"];
// check for category ID
if (String.IsNullOrEmpty(userFirstLetter))
{
// display default category
userFirstLetter = "%";
}
// display requested category
categoryID.Text = string.Format(" ... ({0})", userFirstLetter);
// specify filter for db search
ObjectDataSource1.SelectParameters["UserName"].DefaultValue = userFirstLetter + "%";
// HERE IS WHAT I DON"T KNOW HOW!
// GET SQUIGLY LINE
RefreshGridView(GridView1);
}
请注意上面的大写字母。这就是我尝试调用第一个方法但得到红色下划线的地方。有人可以帮忙吗?谢谢。
I have two methods in the same class and would like to find out how to use the first method in the second one.
// first method
public static void RefreshGridView(GridView GridView1)
{
GridView1.DataBind();
}
// second method
public static void AssignDefaultUserNameLetter(Literal categoryID, ObjectDataSource ObjectDataSource1)
{
// declare variable for filter query string
string userFirstLetter = HttpContext.Current.Request.QueryString["az"];
// check for category ID
if (String.IsNullOrEmpty(userFirstLetter))
{
// display default category
userFirstLetter = "%";
}
// display requested category
categoryID.Text = string.Format(" ... ({0})", userFirstLetter);
// specify filter for db search
ObjectDataSource1.SelectParameters["UserName"].DefaultValue = userFirstLetter + "%";
// HERE IS WHAT I DON"T KNOW HOW!
// GET SQUIGLY LINE
RefreshGridView(GridView1);
}
Please note the capital letters above. That is where I am trying to call the first method but getting the red underline. Can some one help please? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该方法被标记为
static
,但GridView1
看起来像是一个实例变量。您需要更改该方法,以便
AssignDefaultUserNameLetter
不是静态的,或者以其他方式获取 GridView,例如作为参数传入。The method is marked as
static
butGridView1
looks like it is an instance variable.You need to change the method so that
AssignDefaultUserNameLetter
is not static or the GridView is fetched some other way such as passed in as a parameter.您可能不希望这些方法中的任何一个成为 静态 因为它们似乎都对类的实例变量进行操作(这似乎是一种形式)。您将它们设置为
静态
有什么特殊原因吗?You probably don't want either of those methods to be static as they both appear to operate on instance variables of your class (which appears to be a form). Is there any particular reason you made them
static
?