<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" >
                                                <asp:ListItem Value="0">=请选择姓名=</asp:ListItem>
                                            </asp:DropDownList>
<div id="div1" runat="server" style="display: none">
                                <asp:Calendar ID="Calendar2" runat="server" OnDayRender="Calendar2_DayRender" BackColor="White" BorderColor="#69B3E0" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth" Width="100%" BorderStyle="Solid" CellSpacing="1" SelectionMode="None">
            <SelectedDayStyle BackColor="GradientActiveCaption" ForeColor="White" />
            <TodayDayStyle BackColor="#999999" ForeColor="White" />
            <OtherMonthDayStyle ForeColor="#999999" />
            <NextPrevStyle Font-Size="8pt" ForeColor="White" Font-Bold="True" />
            <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" Height="8pt" HorizontalAlign="Center" VerticalAlign="Middle" />
            <TitleStyle BackColor="#1C85C7" Font-Bold="True" Font-Size="Small" ForeColor="White" BorderStyle="Solid" Height="12pt" />
            <DayStyle BackColor="#CCCCCC" />
        </asp:Calendar>       </div> 请问当我选择dropdownlist的选项的时候如何可以令到id为div1这一层无刷新显示,如果不选择默认是隐藏的。
而asp:Calendar这个日历控件执行OnDayRender="Calendar2_DayRender"事件。我是根据dropdownlist选择的id从而变更它的结果,请教各位大侠啊。小弟搞了很久都没搞成烦恼!

解决方案 »

  1.   

    既然局部刷新,其实没有必要用服务器控件,即便用了服务器控件,也不应该将AutoPostBack="true" ,这将导致页面回发并刷新,因此去掉下拉框的该属性至于局部改变div的显示和隐藏,可以如下操作,jquery方式
     $(function () {
            $("#DropDownList2").change(function () {//当下拉框索引发生改变时
                if ($(this).val() == 0) { //如果没有选择,即=请选择姓名= 时,应该是隐藏
                    $("#div1").hide();
                }
                else {
                    $("#div1").show();//如果有值,则显示
                }        });
        })
    另外,日历的话,我建议也用jquery提供的日历插件,因为你的日历选择都会引发页面刷新,而你则需要的是局部修改并刷新,其实整体上都不该采用服务器控件
    Jquery的DatePicker
      

  2.   

    谢谢。但我要用日历来显示在页面,让别人来选择的。而不是点击一个textbox显示日历。Jquery的DatePicker这个我还没用过啊另外,我怎么才可以把dropdownlist选择的值传给后台呢!
      

  3.   

    可以在pageload里面对控件赋值
    这样即使发生页面刷新, 由于仍然进行了赋值,所以页面的数据倒是没问题AutoPostBack="true" 是发生dropdownlist的 selectedindexchange事件的必需属性
    你这里没有selectedindexchange事件的话 这个属性是不需要的
      

  4.   

    <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" >
                                                    <asp:ListItem Value="0">=请选择姓名=</asp:ListItem>
                                                </asp:DropDownList>外面套个updatepanel吧这个最简单了。
      

  5.   

    现在极度混乱我可以根据组别读出所需的姓名但不能把姓名的值传到后台给OnDayRender="Calendar2_DayRender"绑定啊打救!
      

  6.   

     <table>
                                        <tr>
                                            <td>
                                                <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true">  
                                                    <asp:ListItem Value="0">=请选择组别=</asp:ListItem>                                              
                                                </asp:DropDownList>
                                            </td>
                                            <td>
                                                  <asp:UpdatePanel runat="server" UpdateMode="Conditional">
                                                    <ContentTemplate>
                                                         <asp:DropDownList ID="DropDownList2" runat="server">
                                                    <asp:ListItem Value="0">=请选择姓名=</asp:ListItem>
                                                </asp:DropDownList>
                                                    </ContentTemplate>
                                                    <Triggers>
                                                        <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" />
                                                    </Triggers>
                                                  </asp:UpdatePanel>                                          
                                               
                                            </td>
                                        </tr>
                                    </table>private void DownBind2()
        {
            //默认显示分类号为1的所有子类
            string dda = "";
            if (Session["u_qy"].ToString() == "1")
            {
                dda = "select * from tbType  where u_qy='1' order by u_team";
            }
            else if (Session["u_qy"].ToString() == "2")
            {
                dda = "select * from tbType  where  u_qy='2' order by u_team";
            }
            DataTable mytab = this.Get_Dt2(dda);
            //绑牢控件
            this.DropDownList1.DataSource = mytab;
            this.DropDownList1.DataValueField = "u_team";
            this.DropDownList1.DataTextField = "u_team";
            this.DropDownList1.DataBind();        //添加一个空的首行
            this.DropDownList1.Items.Insert(0, new ListItem("=选择组别=", ""));
        } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            string dda = "";
            if (Session["u_qy"].ToString() == "1")
            {
                if (Session["u_jn"].ToString() == "四区动感")
                {
                    dda = "select * from OT_user_table  where u_team='" + this.DropDownList1.SelectedValue + "' and u_jn='四区动感' order by u_name ";
                }
                else if (Session["u_jn"].ToString() == "四区神")
                {
                    dda = "select * from OT_user_table  where u_team='" + this.DropDownList1.SelectedValue + "' and u_jn='四区神' order by u_name ";
                }
                else if (Session["u_jn"].ToString() == "江湛动神" || Session["u_jn"].ToString() == "江湛神")
                {
                    dda = "select * from OT_user_table  where u_team='" + this.DropDownList1.SelectedValue + "' and  (u_jn='江湛动神' or u_jn='江湛神') order by u_name";
                }
                else
                {
                    dda = "select * from OT_user_table  where u_team='" + this.DropDownList1.SelectedValue + "'  and u_jn='" + Session["u_jn"] + "' order by u_name ";
                }
            }
            else if (Session["u_qy"].ToString() == "2")
            {
                string aaaa = Session["u_jn"].ToString();
                if (Session["u_jn"].ToString() == "复合全球通")
                {
                    dda = "select * from OT_user_table  where  u_team='" + this.DropDownList1.SelectedValue + "' and u_jn='复合全球通' order by u_name ";
                }
                else if (Session["u_jn"].ToString() == "四区全球通")
                {
                    dda = "select * from OT_user_table  where u_team='" + this.DropDownList1.SelectedValue + "'  and u_jn='四区全球通'  order by u_team,u_jn ";
                }
                else
                {
                    dda = "select * from OT_user_table  where  u_zg='2' and (u_qy='1' or u_qy='2') and u_team='" + this.DropDownList1.SelectedValue + "'  and u_jn='" + Session["jn"] + "' order by u_team,u_jn ";
                }
            }
            this.DropDownList2.DataSource = Get_Dt(dda);
            this.DropDownList2.DataValueField = "u_Labor_number";
            this.DropDownList2.DataTextField = "u_name";
            this.DropDownList2.DataBind();
            this.DropDownList2.Items.Insert(0, new ListItem("=请选择姓名=", "0"));
        }protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["ok"] != null)
            {
                if (!IsPostBack)
                {                this.Calendar1.VisibleDate = Convert.ToDateTime(DateTime.Now.AddMonths(1));
                    this.Calendar2.VisibleDate = Convert.ToDateTime(DateTime.Now.AddMonths(1));
                    this.DownBind2();            }
            }
            else
            {
                Response.Redirect("../userlogin.aspx");
            }
            
            
        }
     <div id="div1" runat="server">
                                    <asp:Calendar ID="Calendar2" runat="server" OnDayRender="Calendar2_DayRender" BackColor="White" BorderColor="#69B3E0" Font-Names="Verdana" Font-Size="9pt" ForeColor="Black" Height="250px" NextPrevFormat="ShortMonth" Width="100%" BorderStyle="Solid" CellSpacing="1" SelectionMode="None">
                <SelectedDayStyle BackColor="GradientActiveCaption" ForeColor="White" />
                <TodayDayStyle BackColor="#999999" ForeColor="White" />
                <OtherMonthDayStyle ForeColor="#999999" />
                <NextPrevStyle Font-Size="8pt" ForeColor="White" Font-Bold="True" />
                <DayHeaderStyle Font-Bold="True" Font-Size="8pt" ForeColor="#333333" Height="8pt" HorizontalAlign="Center" VerticalAlign="Middle" />
                <TitleStyle BackColor="#1C85C7" Font-Bold="True" Font-Size="Small" ForeColor="White" BorderStyle="Solid" Height="12pt" />
                <DayStyle BackColor="#CCCCCC" />
            </asp:Calendar>       </div>  
     protected void Calendar2_DayRender(object sender, DayRenderEventArgs e)
        {
            string sql = "select * from tbBB where 工号='" + this.DropDownList2.SelectedValue + "'";
            ArrayList arr = new ArrayList();
            ArrayList arr1 = new ArrayList();
            ArrayList arr2 = new ArrayList();
            conn.Open();
            SqlCommand cm2 = new SqlCommand(sql.ToString(), conn);
            SqlDataReader dt1 = cm2.ExecuteReader();
            while (dt1.Read())
            {
                arr.Add(dt1["月份"].ToString());
                arr1.Add(dt1["班次"].ToString());
            }
            conn.Close();
            for (int i = 0; i < arr.Count; i++)
            {
                if (e.Day.Date.Year.ToString() + e.Day.Date.Month.ToString() == arr[i].ToString())
                {
                    string[] strDay = arr1[i].ToString().Split('-');
                    if (strDay[e.Day.Date.Day].ToString() != "0")
                    {
                        e.Cell.Text = "<a id='" + e.Day.Date + "' href='javascript:' onclick=\"sel2('" + e.Day.Date.Day+"-" + strDay[e.Day.Date.Day * 2 - 1].ToString() + "')\" >" + "" + strDay[e.Day.Date.Day * 2 - 1].ToString() + "&nbsp; &nbsp;&nbsp;" + "<font size='4px'><strong>" + e.Day.Date.Day + "</strong></font></a>";
                    }
                }
            }
        }我现在就是需要读取不到DropDownList2传值希望各位大侠打救。
      

  7.   

    你可以把DropDownList1也放到UpdatePanel测试啊。
    如果无刷新,还是完全使用js实现比较好,不要使用服务器控件
      

  8.   

    自动回传?你去看看我的那个帖子更详细。谢谢!
    http://topic.csdn.net/u/20120821/08/7891a813-3ba5-4530-8568-d7b4291805dd.html?52999
      

  9.   

    解决了吗?很简单啊, $("#DropDownList2").change({
       
       $.post("ss.aspx",{"value":selectvalue},function(){
           $("#div1").show();
       });
    });
    selectvalue就是你的DropDownList2的选中值,ss.aspx是你当前或者处理页面,
    ajax请求成功$("#div1").show();显示你的div1,OK