如何访问DropDownList的静态方法 [英] How to access dropdownlist in static method
问题描述
我有以下的静态方法。
public static List<string> GetAutoCompleteData(string StudentId)
{
List<string> result = new List<string>();
using (SqlConnection con = new SqlConnection("Data Source=.;Integrated Security=true;Initial Catalog=SMS"))
{
//using (SqlCommand cmd = new SqlCommand("select StudentId,StudentName from tblStudent where StudentId LIKE '%'+@SearchText+'%'", con))
using (SqlCommand cmd = new SqlCommand("select T1.StudentName,T1.StudentId from tblStudent T1 where StudentId LIKE '%'+@SearchText+'%' except select T2.StudentName, T2.StudentId from tblStudentAcademics T2 where T2.AcademicYear='" +Dropdownvalue + "'", con))
{
con.Open();
cmd.Parameters.AddWithValue("@SearchText", StudentId);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
result.Add(dr["StudentId"].ToString() + "-" + dr["StudentName"].ToString());
}
return result;
}
}
}
我需要的地方Dropdownvalue.Help来写ddlAcadeic.selectedvalue.tostring()我
I need to write ddlAcadeic.selectedvalue.tostring() in place of Dropdownvalue.Help me
推荐答案
DROPDOWNLIST对象是类的非静态成员(网页)和静态方法不能访问不是静态成员。 DropDownList的值传递给当你调用它的静态方法。
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.
的的静态方法定义的
public static List GetAutoCompleteData(string StudentId, string dropdownvalue ) {
//Your code
}
的的静态方法调用的
StaticMethodClass.GetAutoCompleteData("studendId", dropdown.SelectedValue);
这篇关于如何访问DropDownList的静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!