DropDownList的相关操作
1.绑定DropDownList
public void FillCBL(DataSet ds,CheckBoxList cbl)
{
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
cbl.Items.Add(new ListItem(ds.Tables[0].Rows[i]["Name"].ToString(), ds.Tables[0].Rows[i]["ID"].ToString()));
}
cbl.DataBind();
}
}
}
2.javascript访问DropDownList的值
<asp:DropDownList ID="txtADPID" runat="server" onchange="javascript:showADP(this)" >
</asp:DropDownList>
//判断是否显示广告位
function showADP(obj)
{
var divname = document.getElementById("ADPostionName");
//如果是网站广告就又广告位,其它都没有
if(obj.options.value=="AdvS")//取得DropDownList的值
{
divname.style.display="block";
}
else
{
divname.style.display="none";
}
}
3.Javascript获取select的选中值和选中文本
var index = obj.selectedIndex; // 选中索引
var text = obj.options[index].text; // 选中文本
var value = obj.options[index].value; // 选中值
浙公网安备 33010602011771号