/*-----------------------------------------------*/
/*  编号 03 */
/// <summary>
/// HtmlSelect(drop)控件(下拉列表框)进行数据绑定
/// </summary>
/// <param name="drop">HtmlSelect控件</param>
/// <param name="dtbl">作为数据源的DataTable对象</param>
/// <param name="strText">绑定的显示值(DataTextField属性)</param>
/// <param name="strValue">绑定的实际值(DataValueField属性)</param>
/// <returns></returns>
public static string DropBind(HtmlSelect drop,DataTable dtbl,string strText,string strValue)
{
string strRes = strOK; drop.DataSource = dtbl.DefaultView;
drop.DataTextField = strText;
drop.DataValueField = strValue; try
{
drop.DataBind();
}
catch(SqlException ex)
{
strRes = ex.Message;
} return strRes;
}

解决方案 »

  1.   

    string varsql = "select * from product";   public static readonly string connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=d:\\net\\aspx\\xiangmu\\mdb\\CBIC.mdb;uid=admin;pwd=;";
    SqlConnection conn = new SqlConnection(connString);
    conn.Open();
    SqlCommand cmd = new SqlCommand(varsql,conn);
    SqlDataReader myrd=cmd.ExecuteReader();
      DropDownList1.DataSource = myrd;
      DropDownList1.DataTextField = "name";
      DropDownList1.DataValueField = "id";
      DropDownList1.DataBind(); }
      

  2.   

    Sub DropDownList_BindGrid()
        CmdSelect=new OleDbCommand("select * from class order by id",MyConnection)
        MyConnection.Open
    dtrReader=CmdSelect.ExecuteReader()
    dropnews.DataSource=dtrReader
    dropnews.DataTextField="bigclass"
    dropnews.DataValueField="bigclassid"
    dropnews.DataBind()
    dropnews.Items.Insert(0,new ListItem("ALL NEWS",-1))
    dtrReader.close
    MyConnection.Close()
    End Sub-------------------------------
    <asp:dropdownlist id="dropnews" AutoPostBack="true" OnSelectedIndexChanged="dropnews_SelectedIndexChanged" runat="server"/>
      

  3.   

    关于SQL查询的优化是很关键的,不要动不动就"select * from product",浪费时间
      

  4.   

    DropDownList1.DataSource = dst
                DropDownList1.DataTextField = "字段"
                DropDownList1.DataValueField = "字段1"
                DropDownList1.DataBind()
      

  5.   

    up,this problem is very easy