ajax updatepanel

wolf_Knight 2010-02-01 04:05:25
asp.net 页面上面布局如下:
第1行 有个button ID为btnTest,
第2行 是两个用户控件都是downlist,如ID为 dwnA 和 dwnB;
第3行 是一个gridview ID 为grddata;

想使用如下功能
1.单击btnTest时 , 只刷新grddata 数据;
2.单击用户控件dwnA 时,触发SelectedIndexChanged事件, 只刷新加载dwnb数据;
请问用updatepanel该如何布局和设置呢。谢谢大家!


...全文
87 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
wolf_Knight 2010-02-02
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 ab83328523 的回复:]
别再用 updatepanel  了  ,太不好了   
[/Quote]

那用什么呢。你有封装好的控件?
随风落梦 2010-02-02
  • 打赏
  • 举报
回复
关注
ab83328523 2010-02-02
  • 打赏
  • 举报
回复
别再用 updatepanel 了 ,太不好了
wolf_Knight 2010-02-02
  • 打赏
  • 举报
回复
没人知道吗?
wolf_Knight 2010-02-01
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 gnolhh168 的回复:]
1.单击btnTest时 ,    只刷新grddata 数据;  这两个放在一个updatepanel里
  2.单击用户控件dwnA 时,触发SelectedIndexChanged事件, 只刷新加载dwnb数据;这两个dwn放在另一个updatepanel里

然后你说的还有一个导出数据的按钮,是什么意思,放在updatepanel外直接导出啊,据我所知要把gridview数据导出(如excel文件等)页面必然会postback的。
[/Quote]

是的。我页面布局已经定下来了。不能随便改。就是说第一行有查询按钮 btntest 后面跟着一个导出按钮
第2行是查询条件,第3行是gridview 如果全部放在一个updatepanel里面。导出按钮是不能使用的。就是说在布局已经定下来的情况,怎么实现。
Keep-Learning 2010-02-01
  • 打赏
  • 举报
回复
1.单击btnTest时 , 只刷新grddata 数据; 这两个放在一个updatepanel里
2.单击用户控件dwnA 时,触发SelectedIndexChanged事件, 只刷新加载dwnb数据;这两个dwn放在另一个updatepanel里

然后你说的还有一个导出数据的按钮,是什么意思,放在updatepanel外直接导出啊,据我所知要把gridview数据导出(如excel文件等)页面必然会postback的。
polarissky 2010-02-01
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 tzs2304 的回复:]
C# code
if (!IsPostBack)加了没
[/Quote]
升星了啊,恭喜恭喜
polarissky 2010-02-01
  • 打赏
  • 举报
回复
using System;
using System.Web.UI.WebControls;
using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void Button_Click(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
// 更新GridView方法
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
int selectedIndex = this.DropDownList1.SelectedIndex;
string textValue = "你选择了DropDownList1的Index是:" + selectedIndex;
ListItem item = new ListItem(textValue);
if (!DropDownList2.Items.Contains(item))
{
DropDownList2.Items.Add(item);
}
DropDownList2.Text = textValue;
}
}
polarissky 2010-02-01
  • 打赏
  • 举报
回复

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>请选择...</asp:ListItem>
<asp:ListItem>祖国</asp:ListItem>
<asp:ListItem>万岁</asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList>
</ContentTemplate>

</asp:UpdatePanel>
</div>
<div>
<asp:UpdatePanel ID="UpdatePanel2" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:Button ID="Button" runat="server" Text="Button" onclick="Button_Click" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</form>
</body>
</html>
wolf_Knight 2010-02-01
  • 打赏
  • 举报
回复
当然加了。
tzs2304 2010-02-01
  • 打赏
  • 举报
回复

Page_Load() {
if (!IsPostBack) {

}
}

if (!IsPostBack)加了没
wolf_Knight 2010-02-01
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 zengzhan 的回复:]
例子:
C# code<%@ Register Assembly="Microsoft.Web.Atlas" Namespace="Microsoft.Web.UI" TagPrefix="cc1"%><cc1:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True"></cc1:ScriptManager><asp:DropDownList ID="aaa" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlthumbnail_SelectedIndexChanged"></asp:DropDownList><cc1:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate><asp:Label ID="lblatnail" runat="server" Text="" Visible=false></asp:Label><asp:LinkButton ID="lbtnatnail" runat="server" Visible=false>View</asp:LinkButton><br/></ContentTemplate><Triggers><cc1:ControlEventTrigger ControlID="aaa" EventName="SelectedIndexChanged"></cc1:ControlEventTrigger></Triggers></cc1:UpdatePanel>

[/Quote]

谢谢。其实我的写法给你基本差不多。只不过那个下拉框是个用户控件,我公开了选择事件和AutoPostBack属性,我设置断点是看到数据已经赋值给控件了,但是页面却没有显示相关数据出来。
wolf_Knight 2010-02-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 tzs2304 的回复:]
都放在一个updatepanel就可以了
[/Quote]

因为我还有一个button是用来导出数据的。所以想请教如何实现我的要求。
qqzeng-ip 2010-02-01
  • 打赏
  • 举报
回复
例子:
<%@ Register Assembly="Microsoft.Web.Atlas" Namespace="Microsoft.Web.UI" TagPrefix="cc1" %>
<cc1:ScriptManager ID="ScriptManager1" runat="server" EnablePartialRendering="True">
</cc1:ScriptManager>

<asp:DropDownList ID="aaa" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlthumbnail_SelectedIndexChanged">
</asp:DropDownList>
<cc1:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:Label ID="lblatnail" runat="server" Text="" Visible=false></asp:Label>
<asp:LinkButton ID="lbtnatnail" runat="server" Visible=false>View</asp:LinkButton><br />
</ContentTemplate>
<Triggers>
<cc1:ControlEventTrigger ControlID="aaa" EventName="SelectedIndexChanged"></cc1:ControlEventTrigger>
</Triggers>
</cc1:UpdatePanel>

tzs2304 2010-02-01
  • 打赏
  • 举报
回复
都放在一个updatepanel就可以了

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧