vs2005里没有updatePanel,怎样实现无刷新联级下拉列表 有两个DropDownList,分别标识一级类别和二级类别,选中一级类别里的某一项时,二级类别里的列表项自动刷新。 -------------(菜鸟) 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不用updatepanel就用ajax实现联动 UpdatePanel只是微软Ajax框架的很少一部分实际中基本不会应用 我在javascript中怎样才能调用.cs文件中的方法 jquery里有ajax调用的,下载一个jquery帮助手册查查就知道了。用ajaxpro也是个不错的选择。 updatepanel可能是编码量最少的,只需要拖拽上去就行了。下载http://www.asp.net/ajaxlibrary/Download.ashx ajax control toolkit安装后vs2005里就有了。 自己google都不会了?那么我给你google:http://www.google.com.hk/search?q=asp.net+ajax+updatepanel+dropdownlist&hl=zh-CN&newwindow=1&safe=strict&rls=com.microsoft:zh-cn:IE-SearchBox&source=lnt&tbs=lr:lang_1zh-CN%7Clang_1zh-TW&lr=lang_zh-CN%7Clang_zh-TW&sa=X&ei=s8ELTM7LM47CcdfpyZMO&ved=0CAcQpwU 我的资源下载:http://download.csdn.net/source/2188546 我随便写了一个简单的demo,都明白这个demo基本上可以初步开始工作了:<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Test_Default" %><!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"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <td valign="top"> <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="True"> <asp:ListItem>黄河</asp:ListItem> <asp:ListItem Value="长江"></asp:ListItem> <asp:ListItem>美眉</asp:ListItem> <asp:ListItem>神仙</asp:ListItem> </asp:DropDownList> </ContentTemplate> </asp:UpdatePanel> <asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:DropDownList ID="DropDownList2" runat="server" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged" Visible="False" AutoPostBack="True"> </asp:DropDownList> </ContentTemplate> </asp:UpdatePanel> <asp:UpdatePanel runat="server"> <ContentTemplate> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="随机改变图片并测试其它地方的状态是否在回发时不丢失" /> </ContentTemplate> </asp:UpdatePanel> </td> <td align="right" valign="top"> <div style="text-align: left"> <asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional"> <ContentTemplate> <asp:Label ID="Label1" runat="server" EnableViewState="False" Font-Bold="True" ForeColor="#009933"></asp:Label> <br /> <asp:Image ID="Image1" runat="server" Visible="false" /> </ContentTemplate> </asp:UpdatePanel> </div> </td> </tr> </table> </form></body></html>using System;using System.Collections.Generic;using System.Drawing;public partial class Test_Default : System.Web.UI.Page{ protected void Button1_Click(object sender, EventArgs e) { string[] urls = new string[]{ "http://bookpic.newbooks.com.cn/pic/200712/174858/20071218011818365.jpg", "http://asp-net-ajax-chat.smartcode.com/images/sshots/asp_net_ajax_chat_24699.jpeg", "http://www.componentcn.com/UploadFiles/Image/product/Telerik/RadControls%20for%20ASP.NET%20AJAX.gif"}; var newUrl = urls[new Random().Next(3)]; if (this.Image1.ImageUrl != newUrl) { this.Image1.ImageUrl = newUrl; this.Image1.Visible = true; } else { this.Label1.Text = "谢谢观赏图片!"; this.Label1.BackColor = Color.Brown; } this.UpdatePanel2.Update(); } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { this.Label1.Text = "您最近选择了" + this.DropDownList1.SelectedValue + "!"; this.UpdatePanel2.Update(); var ss = new List<string>(); var cnt = new Random().Next(10) + 10; for (var i = 0; i < cnt; i++) ss.Add(this.DropDownList1.SelectedValue + "_" + i.ToString()); //实际上这里应该是从数据库查询 this.DropDownList2.DataSource = ss; this.DropDownList2.DataBind(); this.DropDownList2.Visible = true; this.UpdatePanel3.Update(); } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { this.Label1.Text = "您从另一个选项中选择了" + this.DropDownList2.SelectedValue + "!"; this.UpdatePanel2.Update(); }}这里演示了几个最基本的UpdatePanel编程知识。 仔细硬着头皮看懂#14楼的demo,你才能读懂UpdatePanel基本知识。我随便说几个上面似乎表现到的编程设计知识:1. 页面要分割为许多独立的UpdatePanel(注意UpdateMode属性为"Conditional"),划分这些Panel的原则就是它们并不同时刷新,而当一个Panel不但自己Update的时候还要刷新其它Panel则使用Update方法来进行。2. 我将Label1的EnableViewState属性设置为False,因为它确实在刷新时要自动忘记自己的状态。而旁边的Image1控件,显然需要在刷新时记住自己的状态,所以没有改变EnableViewState属性。3. 实际上你还可以在页面,在任何UpdatePanel之外放一个Button控件用于测试状态。因为当你点击这个原本在后台什么也不干的Button时,如果页面上状态乱了,那么就不要再去写更多的代码了,因为你处理UpdatePanel中各个细节控件时肯定会乱写代码。这个时候,你的精力就应该放在如何让这个Button按钮测试仍然显示出你的状态不会乱。如果不能在编写交互的asp.net程序操作时保持状态,最好就放弃asp.net编程,而去搞十分简单的 html+javascript+asp 编程,搞这种编程的人也能在一些做网页的公司里赚不错的工资的。 在后台给第一个下拉列表绑定值,当第一个下拉列表的值发生改变时,动态加载第二个下拉列表的值,加载第二个下拉列表要用js实现,可以调用xmlhttp 发送到另一个页面执行查询,然后在本页接受返回的查询结果, 创建option,加载到第二个下拉列表。 jquery的ajax方法是除了updatepanel外估计最简单的了楼主嫌麻烦就用updatepanel啊 装个ajax的插件就可以了,2005是2.0版本的,2008是3.5版本的,网上搜搜,多的很 我有例子想要加我或是直接下载:http://download.csdn.net/source/2438083 DataList排序及分页问题 等待高手解答 跪求:水晶报表翻页问题 c# 取载字符串问题,按特定字符串截取 远征... .NET能否通过按钮另外弹出一个窗口,就像JS的window.open一样? 文件上传问题?? 请问在asp.net中怎么使用ubb 洋葱html编辑器控件正式版(1.1)下载新增加设置颜色功能 DATAVIEW筛选的问题 新手,紧急求教??? 求sql 语句 怎么做到读取完页面再读取数据
就用ajax实现联动
用ajaxpro也是个不错的选择。
下载http://www.asp.net/ajaxlibrary/Download.ashx
ajax control toolkit安装后vs2005里就有了。
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td valign="top">
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"
AutoPostBack="True">
<asp:ListItem>黄河</asp:ListItem>
<asp:ListItem Value="长江"></asp:ListItem>
<asp:ListItem>美眉</asp:ListItem>
<asp:ListItem>神仙</asp:ListItem>
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="UpdatePanel3" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"
Visible="False" AutoPostBack="True">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="随机改变图片并测试其它地方的状态是否在回发时不丢失" />
</ContentTemplate>
</asp:UpdatePanel>
</td>
<td align="right" valign="top">
<div style="text-align: left">
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" EnableViewState="False" Font-Bold="True" ForeColor="#009933"></asp:Label>
<br />
<asp:Image ID="Image1" runat="server" Visible="false" />
</ContentTemplate>
</asp:UpdatePanel>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Drawing;public partial class Test_Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
string[] urls = new string[]{
"http://bookpic.newbooks.com.cn/pic/200712/174858/20071218011818365.jpg",
"http://asp-net-ajax-chat.smartcode.com/images/sshots/asp_net_ajax_chat_24699.jpeg",
"http://www.componentcn.com/UploadFiles/Image/product/Telerik/RadControls%20for%20ASP.NET%20AJAX.gif"};
var newUrl = urls[new Random().Next(3)];
if (this.Image1.ImageUrl != newUrl)
{
this.Image1.ImageUrl = newUrl;
this.Image1.Visible = true;
}
else
{
this.Label1.Text = "谢谢观赏图片!";
this.Label1.BackColor = Color.Brown;
}
this.UpdatePanel2.Update();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
this.Label1.Text = "您最近选择了" + this.DropDownList1.SelectedValue + "!";
this.UpdatePanel2.Update();
var ss = new List<string>();
var cnt = new Random().Next(10) + 10;
for (var i = 0; i < cnt; i++)
ss.Add(this.DropDownList1.SelectedValue + "_" + i.ToString()); //实际上这里应该是从数据库查询
this.DropDownList2.DataSource = ss;
this.DropDownList2.DataBind();
this.DropDownList2.Visible = true;
this.UpdatePanel3.Update();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
this.Label1.Text = "您从另一个选项中选择了" + this.DropDownList2.SelectedValue + "!";
this.UpdatePanel2.Update();
}
}这里演示了几个最基本的UpdatePanel编程知识。
楼主嫌麻烦就用updatepanel啊
想要加我
或是直接下载:http://download.csdn.net/source/2438083