获取选中项的Value值: $('select#sel option:selected').val(); 或者 $('select#sel').find('option:selected').val(); 获取选中项的Text值: $('select#seloption:selected').text(); 或者 $('select#sel').find('option:selected').text();
$('select#sel').get(0).selectedIndex;
$('select#sel option:last').attr("index")
$('select#sel')[0].options.length; 或者 $('select#sel').get(0).options.length;
$('select#sel option:first').attr('selected','true') 或者 $('select#sel')[0].selectedIndex = 0;
$('select#sel option:last).attr('selected','true')
$('select#sel')[0].selectedIndex =索引值;索引值=0,1,2....
$('select#sel').attr('value','4'); 或者 $("select#sel option[value='4']").attr('selected', 'true');
$("select#sel option[value='3']").remove();
$(" select#sel option ").eq(索引值).remove();索引值=0,1,2.... 如删除第3个Radio: $(" select#sel option ").eq(2).remove();
$(" select#sel option ").eq(0).remove(); 或者 $("select#sel option:first").remove();
$("select#sel option:last").remove();
$("select#sel").remove();
$("select#sel").append("f");
$("select#sel").prepend("0");
$(' select#sel option ').each(function (index, domEle) { //写入代码 });.net控件dropdownlist动态绑定数据
SqlConnection conn = UtilitySqlClass.OperateDataBase.ReturnConn();
string strSQL = "select * from CompanyType";
SqlDataAdapter ada = new SqlDataAdapter(strSQL, conn);
DataSet ds = new DataSet();
ada.Fill(ds, "CompanyType");
DropDownList1.DataSource = ds.Tables["CompanyType"].DefaultView;
DropDownList1.DataValueField = ds.Tables["CompanyType"].Columns[1].ColumnName;
DropDownList1.DataTextField = ds.Tables["CompanyType"].Columns[1].ColumnName;
DropDownList1.DataBind();
ds.Dispose();
第一种方法:protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SqlConnection conn = UtilitySqlClass.OperateDataBase.ReturnConn();
try
{
conn.Open();
this.DropDownList1.Items.Add("");
string strSQL = "select CompanyType from CompanyType";
SqlCommand com = new SqlCommand(strSQL, conn);
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
this.DropDownList1.Items.Add(dr["CompanyType"].ToString());
}
}
catch (Exception ex)
{
Response.Write("<scirpt>alert('" + ex.Message.ToString() + "')</script>");
}
finally
{
conn.Close();
}
}
}
string ConnString = ConfigurationSettings.AppSettings["ConnectionString"];
//创建一个SqlConnection
SqlConnection Conn = new SqlConnection( ConnString );
string SQL_Select = "select id, ItemName from DDLItem order by id desc";
//构造一个SqlDataAdapter
SqlDataAdapter myAdapter = new SqlDataAdapter( SQL_Select, Conn);
//开始读取数据
Conn.Open();
DataSet dataSet = new DataSet();
myAdapter.Fill( dataSet,"Table1" );
Conn.Close();
//开始绑定DropDownList
//指定DropDownList使用的数据源
DropDownList1.DataSource = dataSet.Tables["Table1"].DefaultView;
//指定DropDownList使用的表里的那些字段
DropDownList1.DataTextField = "ItemName"; //dropdownlist的Text的字段
DropDownList1.DataValueField = "id";//dropdownlist的Value的字段
DropDownList1.DataBind();
con.Open();
SqlCommand cmd = new SqlCommand(strSql,con);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
DropDownList1.Items.Add(new ListItem(dr["status"].ToString(), dr["status_Id"].ToString()));
}
如对本文有疑问,请提交到交流论坛,广大热心网友会为你解答!! 点击进入论坛