首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

ajaxpro的使用有关问题

2012-01-20 
ajaxpro的使用问题我的项目中使用了ajaxpro是为了加载页面时,显示“请稍等……”,但在后台的方法中绑定gridvie

ajaxpro的使用问题
我的项目中使用了ajaxpro是为了加载页面时,显示“请稍等……”,但在后台的方法中绑定gridview去不显示数据。这是我的代码
页面
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_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>
  <script language="JavaScript" type="text/JavaScript">  
  <!--  
  function Working() { //v3.0 \
  
  var a=_Default.aaa(aa)
  alert(a);
  }  
  function aa()
  {
  document.getElementById("div2").style.display="none";
  document.getElementById("div1").style.display="";
  }
  //-->  
  </script>
</head>
<body onload="Working()">
  <form id="form1" runat="server"><div id="div2" runat="server" style="z-index: 1; left: 430px; position: absolute;
  top: 245px;">
  <input type="image" src="busy.gif" />
  &nbsp;&nbsp;请稍等……
  </div>
  <div id="div1" >
  <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333" GridLines="None">
  <Columns>
  <asp:BoundField DataField="name" HeaderText="name" />
  <asp:BoundField DataField="sex" HeaderText="sex" />
  <asp:BoundField DataField="mark4" HeaderText="mark4" />
  <asp:BoundField DataField="year4" HeaderText="year4" />
  </Columns>
  <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
  <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
  <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
  <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
  <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
  <AlternatingRowStyle BackColor="White" />
  </asp:GridView>
  <asp:DropDownList ID="DropDownList1" runat="server">
  </asp:DropDownList></div>
  </form>
</body>
</html>
后台
using System;
using System.Data;
using System.Configuration;
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;

public partial class _Default : System.Web.UI.Page 
{
  protected void Page_Load(object sender, EventArgs e)
  {
  AjaxPro.Utility.RegisterTypeForAjax
  (typeof(_Default));
  if (!IsPostBack)
  {
  // aaa();
  }

  }

  [AjaxPro.AjaxMethod]


  public string aaa()
  {
  DataSet ds = new DataSet();
  try
  {
  SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
  SqlDataAdapter da = new SqlDataAdapter("select top 10 * from tblperson", con);
   
  da.Fill(ds, "tblperson");
  this.DropDownList1.DataTextField = "name";
  this.DropDownList1.DataValueField = "name";
  this.DropDownList1.DataSource = ds;
  this.DropDownList1.DataBind();





  this.GridView1.DataSource = ds;
  this.GridView1.DataBind();
  }
  catch (Exception e){

  Response.Write(e);
  }
  return "123";
  }
   
}


[解决办法]
两个错误
一、using没有引用ajaxpro
二、你不能在后台用ajax方法对服务器控件进行操作,那是无效的,你应该是返回一个结果集(如DataSet)给前台用js操作
按你上面的操作,你最后的"123"都返回不到前台的

热点排行