大概猜测你的意思是做查询。想dropdownlist bind数据
private void DropListBind1()
{
//方法绑定DropDownList控件的方法   2002-07-03
sysxn conn=new sysxn();
myConn=conn.MyConn();
myConn.Open();
string strlist="select distinct id from table";
SqlDataAdapter myCommand = new SqlDataAdapter(strlist, myConn);
DataSet ds = new DataSet();
myCommand.Fill(ds,"table");
DDListChild.DataSource =ds;
DDListChild.DataTextField = "id";
DDListChild.DataValueField = "id";
DDListChild.DataBind();
myConn.Close();
}

解决方案 »

  1.   

    This is a Simple Example,you try:
    a.aspx:
    ...
    <form id="example" method="post" runat="server">
    <asp:label id="Label1" Runat="server">选择名称:</asp:label><asp:dropdownlist id="ddl" Runat="server" OnSelectedIndexChanged="ChangeSelection" AutoPostBack="true"></asp:dropdownlist><br><asp:datagrid id="DataGrid1" Runat="server" AutoGenerateColumns="false">
      <COLUMNS>
      ......
     </COLUMNS>
    </asp:datagrid>
    </form>
    ...
    a.aspx.cs:
    ...
    void Page_Load(Object o, EventArgs e)
    {
      string ConnString ="data source=local; initial catalog=your database    name;uid=sa;pwd=";//你的连接字符串 
     SqlConnection oConn = new SqlConnection(ConnString);
     oConn.Open();
    if (!IsPostBack)
    {
    BindData();
    }
    }protected void BindData()
    {
    BindDropDown("select * from your table name","id","mc",dd1);
    string mc1 = dd1.Items.FindByValue(dd1.SelectedItem.Value).ToString();
    DataGrid_Changed(mc1);
    }//通用的DropDownList绑定方法:
    protected void BindDropDown(string sSQL, string sValueField, string sTextField, DropDownList dropdown)
    {
    SqlConnection oConn = new SqlConnection(ConnString);
    oConn.Open();
    SqlCommand cmd = new SqlCommand(sSQL, oConn);
    SqlDataReader dr = cmd.ExecuteReader();
    dropdown.DataSource = dr;
    dropdown.DataValueField = sValueField;
    dropdown.DataTextField = sTextField;
    dropdown.DataBind();
    dr.Close();
    dropdown.SelectedIndex = 0;
    }protected void ChangeSelection(Object sender, EventArgs e)
    {
    DataGrid1.CurrentPageIndex = 0;
    DropDownList d = (DropDownList)sender;
    if ( d == dd1)
    {
              string mc1 = dd1.Items.FindByValue(dd1.SelectedItem.Value).ToString();
              DataGrid_Changed(mc1);
    }
    }protected void DataGrid_Changed(string str_xx)
    {
    string sqlstring = "Select * From your table name Where Column='"+str_xx+"'";
    SqlDataAdapter mycommand = new SqlDataAdapter(sqlstring,ConnString);
    DataSet ds = new DataSet();
    DataGrid1.DataSource = dv;
    DataGrid1.DataBind();
    mycommand.SelectCommand.Connection.Close();
    }
      

  2.   

    string sql;
                               ......与数据库联接后........
    sql="select f_code,f_name from tab_group";
    OleDbDataAdapter myda=new OleDbDataAdapter (sql,myconn);
    DataSet myds=new DataSet ();
    myda.Fill (myds,"tab_group");
    ///////////f_group为下拉选择框///////////////
    f_group.DataSource =myds.Tables ["tab_group"];
    f_group.DataTextField="f_name";
    f_group.DataValueField ="f_code";
    f_group.DataBind ();
    myconn.Close ();
      

  3.   

    private void DropListBind1()
    {
    //方法绑定DropDownList控件的方法   2002-07-03
    sysxn conn=new sysxn();
    myConn=conn.MyConn();
    myConn.Open();
    string strlist="select distinct id from table";
    SqlDataAdapter myCommand = new SqlDataAdapter(strlist, myConn);
    DataSet ds = new DataSet();
    myCommand.Fill(ds,"table");
    DDListChild.DataSource =ds;
    DDListChild.DataTextField = "id";
    DDListChild.DataValueField = "id";
    DDListChild.DataBind();
    myConn.Close();
    }
      

  4.   

    private void ReBindDropDownList()
    {
    SqlDataAdapter Adapter=new SqlDataAdapter("select * from T_Visit_Way",Conn);
    DataSet PlanSet=new DataSet();
    Adapter.Fill(PlanSet,"T_Visit_Way");
    for(int i=0;i<PlanGrid.Items.Count;i++)
    {
    DropDownList List=(DropDownList)PlanGrid.Items[i].FindControl("VisitDorpdow");
    List.DataSource=PlanSet;
    List.DataTextField="VisitWay";
    List.DataValueField="VisitWayID";
    List.DataBind();
    }
    }
      

  5.   

    问题已解决,具体看http://www.csdn.net/expert/topic/617/617836.xml
    散分拉
      

  6.   

    public void BindDropDownList(DropDownList aDropDownList,string SelectState,string DataValueField,string[] DataTextField,string tableName,string databaseName,string serverName)
    {
    m=new Methods();
    ArrayList AL=new ArrayList();
    aDropDownList.Items.Clear();
    int i=1;
    string TextField=null;
    string[]TempDataTextField=new string[DataTextField.Length+1];
    TempDataTextField[0]=DataValueField;
    while(i<TempDataTextField.Length)
    {
    TempDataTextField[i]=DataTextField[i-1];
    i++;
    }
    string[]fieldName=TempDataTextField;
    string[]conditionName={"id","IState"};
    string[]condition={">","="};
    string[]conditionValue={"0","1"};
    m.Return_Select(AL,fieldName,conditionName,condition,conditionValue,"and",tableName);
    i=1;

    while(i<TempDataTextField.Length)
    {
    if(i==TempDataTextField.Length-1)
    {
    TextField=TextField+TempDataTextField[i];
    }
    else
    {
    TextField=TextField+TempDataTextField[i]+"+";
    }
    i++; }
    AL[0]=AL[0]+" order by "+TextField;
    SqlDataReader dr=m.Return_DataReader(AL,databaseName,serverName);
    string addItem=null;
    int j=0;
    i=1;
    while(dr.Read())
    {
    aDropDownList.Items.Add("");
    aDropDownList.Items[j].Value=dr[DataValueField].ToString();
    while(i<TempDataTextField.Length)
    {
    addItem=addItem+"  "+dr[TempDataTextField[i]].ToString();
    i++;
    }

    aDropDownList.Items[j].Text=addItem;
    addItem=null;
    j++;
    i=1;
    }
    if(SelectState=="true")
    {
    aDropDownList.Items.Insert(0,"----请选择----");
    }
    }