C# Using a Method in Another Method in the Same Class
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.
The method is marked as static
but GridView1
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
?
精彩评论