DropDownList赋值,绑定,传值

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <table border=0 cellpadding=0 cellspacing=0><form name=meizz>
   <tr><td>
     <select id=list1 size=8 οndblclick="moveOption(this, this.form.list2)">
       <option value=A>aaaaaaaaaa
       <option value=B>bbbbbbbbbb
       <option value=C>cccccccccc
       <option value=D>dddddddddd
       <option value=E>eeeeeeeeee
       <option value=F>ffffffffff
       <option value=G>gggggggggg
       <option value=H>hhhhhhhhhh
     </select></td>
   <td width=40 align=center>
     <input name=add type=button value=">>>" οnclick="moveOption(this.form.list1, this.form.list2)"><br><br>
     <input name=sub type=button value="<<<" οnclick="moveOption(this.form.list2, this.form.list1)">
   </td><td>
     <select id=list2 size=8 οndblclick="moveOption(this, this.form.list1)">
     </select>
   </td></tr></form>
</table>

<script language="JavaScript"><!--
function moveOption(e1, e2){
     try{
         var e = e1.options[e1.selectedIndex];
         e2.options.add(new Option(e.text, e.value));
         e1.options.remove(e1.selectedIndex);
     }    catch(e){}
}
//--></script>

</BODY>
</HTML>  

<div style="position: absolute; top: 10; right: 10; width: 148; height: 18;cursor:hand">
<input type="button" name="Button" value="查看源代码" onClick= 'window.location = "view-source:" + window.location.href'></div>
-------------------------------------------------------------------
-----------------------------绑定好的下拉框,再加一行“--请选择--” 开始
 string sqlseng1 = "select * from Bumen";
            SqlDataReader dr = DBHelper.GetReader(sqlseng1);
            ddlbumen.DataSource = dr;
            ddlbumen.DataValueField = "bumenname";
            ddlbumen.DataTextField = "bumenname";
            ddlbumen.DataBind();

            dr.Close();

            ListItem lit = new ListItem();
            lit.Text = "—请选择—";
            lit.Value = "—请选择—";
            ddlbumen.Items.Add(lit);
            ddlbumen.SelectedValue = "—请选择—";
-----------------------------绑定好的下拉框,再加一行“--请选择--” 结束
-----------------------------------------------------------------------------------------------------------------------
this.DropDownList3.Items.Insert(0, new ListItem("请选择"));
--

             DropDownList1.SelectedValue = trade.Tradesort.Id.ToString();   //默认选中值.传来的值 。有时不可用,下面有可用的
--
------------

ListItem lit = new ListItem();
            lit.Text = "—请选择—";
            lit.Value = "—请选择—";
            ddlbumen.Items.Add(lit);
            ddlbumen.SelectedValue = "—请选择—";
----------------
for (int i = 0; i < list.Count; i++)
        {
            pm = list[i];
            //pm.Pro_id
            propm = new product();
            probll = new productbll();
            prolist = new List<product>();
            prolist = probll.get_productby_id(Convert.ToInt32(pm.Pro_id));

            for (int j = 0; j < prolist.Count; j++)
            {
                ListItem lit = new ListItem();
                lit.Text = prolist[i].Name.ToString();
                lit.Value = prolist[i].Id.ToString();
                this.drp_product.Items.Insert(0, lit);
            }
        }
-------------------------------------------------------------------------------------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs" Inherits="Test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    

<script> 
function showHide(obj){     //隐现层的函数 
sh={block:"none",none:"block"} 
//层的display属性值在"block"和"none"间不断轮换, 
//达到轮换隐藏和显示的效果 
oOption.runtimeStyle.display=sh[oOption.currentStyle.display] } 
</script> 

<!--鼠标移上id为oOption的对象时执行本段代码--> 
<script event="onmouseover" for="oOption"> 
obj=event.srcElement 
if(obj.tagName=="TD"){//判断onmouseover事件是否发生在单元格上 
//设置事件发生所在的单元格的背景颜色 
   obj.style.backgroundColor="#dedede" 
//设置事件发生所在的单元格的字体颜色 
   obj.style.color="#FFFFFF" 
</script>

<!--鼠标从id为oOption的对象上移开时执行本段代码--> 
<script event="onmouseout" for="oOption"> 
obj=event.srcElement 
if(obj.tagName=="TD"){        //判断onmouseout事件是否发生在单元格上 
//设置事件发生所在的单元格的背景颜色 
   obj.style.backgroundColor="#FFFFFF" 
   obj.style.color="#000000"//设置事件发生所在的单元格的字体颜色 
</script>

<!--id为oOption的对象被单击时执行本段代码--> 
<script event="onclick" for="oOption"> 
obj=event.srcElement 
if(obj.tagName=="TD"){ //判断onmouseover事件是否发生在单元格上 
    showHide()        //隐藏层 
//设置id为oSelect的对象内的文本为被点击的单元格内的文本 
    oSelect.innerText=obj.innerText 
//设置id为C_Select的对象内的值为被点击的 
//单元格的自定义属性value的值 
    C_Select.value=obj.value                       
    //window.open(obj.value)                  //测试跳转菜单功能 
</script> 
<style> 
body,td{font-size:12px} 
.over{color:#dedede} 
.out{color:#333333} 
#oOption{ 
scrollbar-face-color:#FFFFFF; 
scrollbar-shadow-color:#C1C1BB; 
scrollbar-highlight-color:#C1C1BB; 
scrollbar-3dlight-color:#EBEBE4; 
scrollbar-darkshadow-color:#EBEBE4; 
scrollbar-track-color:#F4F4F0; 
scrollbar-arrow-color:#CACAB7; 
position:absolute;display:none;width:75px;height:80px; 
overflow:scroll;overflow-x:hidden; 
border:#333333 1px solid;border-top:none;cursor:default 
</style> 
<table width="75" border="0" cellspacing="0" cellpadding="0"> 
<tr><td> 
<table width="100%" bordercolor="#666666" border=1 style="border-collapse:collapse;cursor:default" οnclick="showHide()"> 
<tr> 
<td align="center"> 
<input type="hidden" name="C_Select" id="C_Select"> 
<span id="oSelect">下拉选项</span></td><td align="center" width="14"><span style="font-family: Webdings;colro:#CACAB7" οnmοuseοver="this.className=’over’" οnmοuseοut="this.className=’out’">6</span></td> 
</tr> 
</table> 
</td> 
</tr> 
<tr> 
<td><div id="oOption" onselectstart="return false"> 
<table cellsapcing="0" cellspadding="3" border="0" width="100%"> 
<tr><td value="http://www.flash8.net">闪吧</td></tr> 
<tr><td value="http://www.blueidea.com">经典</td></tr> 
<tr><td value="http://www.5d.cn">5D</td></tr> 
<tr><td value="http://www.sina.com">新浪</td></tr> 
<tr><td value="http://www.sohu.cn">搜狐</td></tr> 
<tr><td value="http://www.163.com">网易</td></tr> 
<tr><td value="http://www.etang.com">亿唐</td></tr> 
</table> 
</div></td> 
</tr> 
</table>

    </div>
    </form>
</body>
</html>

----------------------------------------------------------------------------------------------------------protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           
            int year = DateTime.Now.Year;

            for (int beginYear = year; beginYear > 2000; beginYear--)
            {

                DropDownList1.Items.Add(beginYear.ToString());
            }
        }
    }-
---------------------------------------------------------------------------------------------------------------------
传值
if (!string.IsNullOrEmpty(proid))
            {
                productinfo = productinfoibll.GetEntity(proid);
                ddlProduct.DataSource = lprotduct;
                ddlProduct.DataTextField = "productName";
                ddlProduct.DataValueField = "productId";
                ddlProduct.DataBind();
                //ddlProduct.SelectedValue = proid;
                ListItem lit = new ListItem();
                lit.Text = productinfo.productName;
                lit.Value = productinfo.productId;
                ddlProduct.Items.Insert(0, lit);
            }
posted @ 2022-03-23 08:47  离。  阅读(68)  评论(0编辑  收藏  举报