ajax 更新 Datalist 的问题

wendaocy 2008-10-07 02:38:58
本人做个搜索,首次登陆只有搜索表单,点击按钮局部刷新出现一个Datalist 显示搜索结果。想用MS 的ajax 实现,弄了一上午,发现不对劲,请高手指点指点啊,小弟不胜感激。
前台部分:
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<div id="news_text" style="text-align:center; height:300px;">
<table cellpadding="0" cellspacing="0" style="border-top-style: none; border-bottom: #FF8200 1px solid;border-left: #FF8200 1px solid;border-right: #FF8200 1px solid; width: 952px; height: 300px;" >
<tr>
<td height="419" valign="top" style="width: 714px; height: 300px; border-right: #FF8200 1px dotted;">
<div id="text_content" style="font-size: 12px; color: dimgray" >
    
<br />

<div id="search_style" align="center" >
<table border="0" cellpadding="0" cellspacing="0" style="border-top: #99cc33 1px solid; border-left: #99cc33 1px solid; border-bottom-width: 1px; border-bottom-color: #99cc33; border-right-width: 1px; border-right-color: #99cc33;">
<tr>
<td colspan="3" style="border-bottom: #99cc33 1px solid;background-color:#C5FDB7; border-right: #99cc33 1px solid; border-left-width: 1px; border-left-color: #99cc33; height: 33px;">
高级搜索</td>
</tr>
<tr>
<td style="width: 118px; background-color: border-top-width: 1px; border-right: #99cc33 1px solid; border-left-width: 1px; border-left-color: #99cc33; border-top-color: #99cc33; border-bottom: #99cc33 1px solid; height: 35px;" align="right">
主题词: </td>
<td colspan="2" style="width: 437px; border-right: #99cc33 1px solid; border-bottom: #99cc33 1px solid; height: 35px;" align="left">
 <input id="Text1" style="width: 415px" type="text" /></td>
</tr>
<tr>
<td style="width: 118px; border-right: #99cc33 1px solid; border-bottom: #99cc33 1px solid;" align="right">
搜索分类: </td>
<td colspan="2" style="width: 437px; height: 35px; border-right: #99cc33 1px solid; border-bottom: #99cc33 1px solid;" align="center">
 按标题:<input id="Radio1" name="radio1" checked type="radio" />
按内容: <input id="Radio2" name="radio1" type="radio" /></td>
</tr>
<tr >
<td style="width: 118px; border-right: #99cc33 1px solid; border-bottom: #99cc33 1px solid;" align="right"> 按时间:  </td>
<td colspan="2" style="height: 35px; width: 437px; border-right: #99cc33 1px solid; border-bottom: #99cc33 1px solid;" align="center" valign="middle">
 从:<asp:TextBox runat="server" id="Text2" style="width: 107px" type="text" />
<asp:ImageButton runat="Server" ID="Image1" ImageUrl="images/Calendar_scheduleHS.png" AlternateText="Click to show calendar" />

<cc1:CalendarExtender ID="CalendarExtender" runat="server" CssClass="ajax__calendar" Format="yyyy-MM-dd" TargetControlID="Text2" PopupButtonID="Image1" />
  到:<asp:TextBox id="Text3" runat="server" style="width: 107px" type="text" /></asp:TextBox>
<asp:ImageButton runat="Server" ID="ImageButton1" ImageUrl="images/Calendar_scheduleHS.png" AlternateText="Click to show calendar" />
<%-- <cc1:CalendarExtender ID="CalendarExtender" runat="server" />
--%>
<cc1:CalendarExtender ID="CalendarExtender1" runat="server" CssClass="ajax__calendar" Format="yyyy-MM-dd" TargetControlID="Text3" PopupButtonID="ImageButton1" /></td>
</tr>
<tr >
<td style="width: 118px; border-right: #99cc33 1px solid; border-bottom: #99cc33 1px solid;" align="right"> 按系统资源分类: </td>
<td colspan="2" style="height: 34px; width: 437px; border-right: #99cc33 1px solid; border-bottom: #99cc33 1px solid;" align="center" >
 <asp:DropDownList ID="DropDownList1" runat="server" Width="288" style="color:#999999">
<asp:ListItem>
---- 选择系统资源分类 ----
</asp:ListItem>
</asp:DropDownList> </td>
</tr>
<tr>
<td rowspan="2" style="width: 118px; height: 34px; border-right: #99cc33 1px solid; border-bottom: #99cc33 1px solid;" align="right">  </td>
<td colspan="2" style="height: 34px; width: 437px; border-right: #99cc33 1px solid; border-bottom: #99cc33 1px solid;" align="center">
 精确:<input id="Radio5" name="radio2" checked type="radio" />  模糊:<input id="Radio6" name="radio2" type="radio" />(速度较慢)</td>
</tr>
<tr>

<td colspan="2" style="height: 37px; width: 437px; border-right: #99cc33 1px solid; border-bottom: #99cc33 1px solid;" align="center">
<Button id="Submit1" class="button" type="button" onMousemove="this.className='button_on'" onMouseout="this.className='button'" onclick="return CallServer(Label1)" TabIndex="8" >开始搜索</Button></td>
</tr>
</table>
</div>
<div id="Label1" style="border-right: darkturquoise 1px solid;border-top: darkturquoise 1px solid; border-left: darkturquoise 1px solid; width: 230px;filter:alpha(opacity=60); position:absolute; z-index:2; border-bottom: darkturquoise 1px solid; height: 26px; background-color: paleturquoise; display:none; left: 320px; top: 470px">

</div>
<div id="about" style="text-align:center;">
<asp:UpdatePanel UpdateMode="Conditional" ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DataList ID="result_list" runat="server" ShowFooter="false" ShowHeader="false" >
<ItemTemplate>
<%#Eval("New_Title").ToString() %>
</ItemTemplate>
</asp:DataList>
</ContentTemplate>
<Triggers >
<asp:AsyncPostBackTrigger ControlID="result_list" />
</Triggers>
</asp:UpdatePanel>
......
...全文
162 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
wendaocy 2008-10-07
  • 打赏
  • 举报
回复
我试试看看。
weinaxxc 2008-10-07
  • 打赏
  • 举报
回复
你瞎搞啊,到底你用哪个?UPDATEPANEL还是ICallbackEventHandler
用了UPDATEPANEL就不要用ICallbackEventHandler,后台代码的写法跟原来一样,不需要什么特殊的写法,改咋写就咋写,搜索完以后将搜索栏隐藏,结果显示,这些都在updatepanel里面进行,设置好TRIGGER
wendaocy 2008-10-07
  • 打赏
  • 举报
回复
没有高手嘛 急啊
wendaocy 2008-10-07
  • 打赏
  • 举报
回复
自己顶一下,前台的有点长。呵呵。
wendaocy 2008-10-07
  • 打赏
  • 举报
回复
后台部分:


using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using Dzw;

public partial class Search_News : System.Web.UI.Page,System.Web.UI.ICallbackEventHandler
{
DataSet Ds = new DataSet();
PageBase DzwBase = new PageBase();
public string result;
public string connection = System.Configuration.ConfigurationSettings.AppSettings["DZW2008ConnectionString2"];
protected void Page_Load(object sender, EventArgs e)
{
string sql = "SELECT DISTINCT [Menu_Id], [Menu_Name] FROM [Dz_Menu] WHERE (([Parent_Id] IS NULL) AND ([IsDel] = 0)) ORDER BY [Menu_Name]";
SqlDataAdapter adapter = new SqlDataAdapter(sql,connection);
adapter.Fill(Ds);
for (int i = 0; i < Ds.Tables[0].Rows.Count; i++)
{
ListItem list = new ListItem();
list.Value = Ds.Tables[0].Rows[i]["Menu_Id"].ToString();
list.Text = "|————————" + Ds.Tables[0].Rows[i]["Menu_Name"].ToString() + "————————";
DropDownList1.Items.Add(list);
//DropDownList1.Items.Add(new ListItem("|————————" + Ds.Tables[0].Rows[i]["Menu_Name"].ToString(), Ds.Tables[0].Rows[i]["Menu_Id"].ToString()) + "————————");
DropDownList1.DataBind();
}
PostBackTrigger tri = new PostBackTrigger();
tri.ControlID = "result_list";
UpdatePanel1.Triggers.Add(tri);
this.ScriptManager1.RegisterPostBackControl(this.result_list);
}

#region ICallbackEventHandler 成员

public string GetCallbackResult()
{
return result;
}

public void RaiseCallbackEvent(string eventArgument)
{
string[] param;
param = eventArgument.Split('|');
// DzwBase.DBOpen();
DataSet sDs = new DataSet();
string sql = "select * from Dz_News where New_Title like '%"+ param[0] +"%' order by Add_time Desc";
SqlDataAdapter Adapter = new SqlDataAdapter(sql, connection);
Adapter.Fill(sDs);
result_list.DataSource = sDs.Tables[0].DefaultView;
result_list.DataBind();
// DzwBase.DBClose();
result = "yes";

}

#endregion
}

62,041

社区成员

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

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

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

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