Dropdownlist问题请教
SqlConnection conn = db.createcon();conn.Open();
string sql = "select distinct userclass from Userinfo";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader sdr = cmd.ExecuteReader();
this.Ddluserclass.DataSource=sdr;
this.Ddluserclass.DataTextField = "Userclass";
this.Ddluserclass.DataValueField = "Userclass";
this.Ddluserclass.DataBind();
conn.Close(); //以上语句将用户班级帮定到下拉列表框Ddluserclass中
在根据用户班级查询时:
string userclass = this.Ddluserclass.SelectedValue;/本句是否有错(列表框值不是手动输入而是动态帮定的)
SqlConnection conn = db.createcon();
conn.Open();
string licenfind = "select * from userinfo where userclass='" + userclass + "'";
SqlDataAdapter sda = new SqlDataAdapter(licenfind, conn);
DataSet ds = new DataSet();
sda.Fill(ds);
this.Gvliceninfo.DataSource = ds;
this.Gvliceninfo.DataBind();
conn.Close();
问题2
按班级查询时,无论选择列表框中的哪个项,都会默认将第一项对应的内容选出来,这是怎么回事? --------------------编程问答-------------------- 绑定的语句要放在if(!ispostback)里
Ddluserclass 的autopostback=true; --------------------编程问答-------------------- SqlDataReader sdr = cmd.ExecuteReader();
this.Ddluserclass.DataTextField = "Userclass";
this.Ddluserclass.DataValueField = "Userclass";
这里的问题
this.Gvliceninfo.DataSource = ds;
你把整个表都绑定上去了 --------------------编程问答-------------------- 在绑定班级时设置下拉列表autopostback=true --------------------编程问答-------------------- --------------------编程问答-------------------- 没加if(!ispostback)语句..
--------------------编程问答-------------------- 支持搂主,收藏 --------------------编程问答-------------------- 顶楼上的..``~ --------------------编程问答-------------------- 谢谢大家了,弄出来了 --------------------编程问答-------------------- 什么呀 --------------------编程问答--------------------
补充:.NET技术 , ASP.NET