How to access dropdownlist in static method

前端 未结 1 1472
感情败类
感情败类 2021-01-14 09:36

I have the following static method.

public static List GetAutoCompleteData(string StudentId)
    {
            List result = new          


        
相关标签:
1条回答
  • 2021-01-14 10:11

    Dropdownlist object is non static member of your class (Web Page) and static methods can not access not static members. Pass the dropdownList value to static method when you call it.

    Static Members

    Static methods and properties cannot access non-static fields and events in their containing type, and they cannot access an instance variable of any object unless it is explicitly passed in a method parameter.

    Static method definition

    public static List GetAutoCompleteData(string StudentId, string dropdownvalue ) {
      //Your code
    }
    

    Static method call

    StaticMethodClass.GetAutoCompleteData("studendId", dropdown.SelectedValue);
    
    0 讨论(0)
提交回复
热议问题