COMBOBOX C#数据库

来源:百度知道 编辑:UC知道 时间:2024/06/23 07:49:01
我要将P_SALES表中的P_STOREID 和 combobox1这个下拉列表框进行绑定,我是这么写的,可是运行的时候显示不出来,不知道错在哪里,各位大虾帮忙看看错在哪里,怎么改

private void comboBox1_SelectedIndexChanged(object sender, System.EventArgs e)
{
DataBind();
string strSql="select distinct p_storeid from p_sales where p_date='081230'";
comboBox1.DataSource=this.SqlGetDataSet(strSql,true).Tables[0];
}
private void DataBind()
{
string strSql="select distinct p_storeid from p_sales where p_date='081230'";
comboBox1.DataSource=this.SqlGetDataSet(strSql,true).Tables[0];
}

private void DataBind()
{
string strSql="select distinct p_storeid from p_sales where p_date='081230'";
comboBox1.DataSource=this.SqlGetDataSet(strSql,true).Tables[0];
comboBox1.DataBind();//这绑定下
}
comboBox1_SelectedIndexChanged这个事件里你调用自身的绑定?
设置好DataSource,后要DataBind();下

前台
<asp:DropDownList id="combobox1" runat="server" AutoPostBack="True" onselectedindexchanged="ddlrefectory_SelectedIndexChanged"/>

要加AutoPostBack="True"

后台要写绑定列
this.combobox1.DataTextField="列名";
this.combobox1.DataValueField="列名";
this.combobox1.DataBind();
不明白在问我吧

//要绑定列
this.combobox1.DataTextField="列名";
this.combobox1.DataValueField="列名";
//然后再Bind()下
this.combobox1.DataBind();

1,2楼在忽悠人
首先检查一下你的SQL语句真的查询到数据了吗
private void DataBind()
{
string str