在webmethod中获取简单的下拉值

时间:2014-06-25 07:45:54

标签: c# asp.net

下面是我的代码,其中想要使用dropdownlist但我无法调用其id:错误显示该对象需要静态方法。

    [System.Web.Script.Services.ScriptMethod()]
        [System.Web.Services.WebMethod]
        public static List<string> GetCity(string prefixText)
        {
            DataTable dt = new DataTable();
            string constr = ConfigurationManager.ConnectionStrings["mycon"].ToString();
            SqlConnection con = new SqlConnection(constr);
            con.Open();
SqlCommand cmd = new SqlCommand("select * from tbl_group where Group_Name=" + drpgovtypelcns1.Selecteditem.Text, con);

            cmd.Parameters.AddWithValue("@Group_Name", prefixText);
            SqlDataAdapter adp = new SqlDataAdapter(cmd);
            adp.Fill(dt);
            List<string> CityNames = new List<string>();
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                CityNames.Add(dt.Rows[i][1].ToString());
            }
            return CityNames;
        }

0 个答案:

没有答案