<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从而变更它的结果,请教各位大侠啊。小弟搞了很久都没搞成烦恼!
<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从而变更它的结果,请教各位大侠啊。小弟搞了很久都没搞成烦恼!
解决方案 »
- [求助]asp.net遇到无法访问已关闭的资源集
- 棘手问题:处理应用程序池 ' AppPool ' A 进程遇到与 World Wide Web 发布服务致命通信错误
- Access 批量删除
- 关于编码的问题
- [馨郁星愿]记得思归大哥以前发一篇文章,用Datagird进行分页,vb.net代码的,哪位知道的麻烦贴一下Url
- webdiyer,你的控件的问题
- Web 应用中如何将前端事件回传给后台的 Server
- 孟子老大,求救呀!!!这两天为了这个问题把分都问没了!!!!急救!!1
- 计算当年的周和每周的日期
- asp.net mvc 使用uploadify 没有效果啊 (急急急)
- ASP.NET项目中namespace的问题
- ASP.NET MVC3 在controller中如何为新建的记录新建关联记录?
$(function () {
$("#DropDownList2").change(function () {//当下拉框索引发生改变时
if ($(this).val() == 0) { //如果没有选择,即=请选择姓名= 时,应该是隐藏
$("#div1").hide();
}
else {
$("#div1").show();//如果有值,则显示
} });
})
另外,日历的话,我建议也用jquery提供的日历插件,因为你的日历选择都会引发页面刷新,而你则需要的是局部修改并刷新,其实整体上都不该采用服务器控件
Jquery的DatePicker
这样即使发生页面刷新, 由于仍然进行了赋值,所以页面的数据倒是没问题AutoPostBack="true" 是发生dropdownlist的 selectedindexchange事件的必需属性
你这里没有selectedindexchange事件的话 这个属性是不需要的
<asp:ListItem Value="0">=请选择姓名=</asp:ListItem>
</asp:DropDownList>外面套个updatepanel吧这个最简单了。
<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() + " " + "<font size='4px'><strong>" + e.Day.Date.Day + "</strong></font></a>";
}
}
}
}我现在就是需要读取不到DropDownList2传值希望各位大侠打救。
如果无刷新,还是完全使用js实现比较好,不要使用服务器控件
http://topic.csdn.net/u/20120821/08/7891a813-3ba5-4530-8568-d7b4291805dd.html?52999
$.post("ss.aspx",{"value":selectvalue},function(){
$("#div1").show();
});
});
selectvalue就是你的DropDownList2的选中值,ss.aspx是你当前或者处理页面,
ajax请求成功$("#div1").show();显示你的div1,OK