求教Jquery的Ajax事件
时间:2010-10-15 来源:hbgdluck
脚本代码:
$("#drpRegion").change(function(){
var id=$("#drpRegion").val();
if(id!=0)
{
$("#lbregion").html("");
$.ajax({
type:"POST",
url:"addrecordplan.aspx?regionid="+id,
datatype:"html",
success:function(data)
{
}
})
}
});
前台代码:
<tr>
<td align="left" width="100">
区域:
</td>
<td>
<asp:DropDownList ID="drpRegion" runat="server" AutoPostBack="false"
onselectedindexchanged="drpRegion_SelectedIndexChanged1">
</asp:DropDownList>
<asp:Label ID="lbregion" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td align="left" width="100">
镜头:
</td>
<td>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="100%" CssClass="gridview_m">
<Columns>
<asp:BoundField DataField="name" HeaderText="设备名称" />
<asp:BoundField DataField="regionname" HeaderText="区域名称" />
</Columns>
</asp:GridView>
</td>
</tr>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["regionid"] != null)
{
Bind(Request.QueryString["regionid"]);
}
else
{
Page.RegisterStartupScript("", "<script>top.location.href='../Login.aspx'</script>");
}
}
}
///绑定GridView 的方法
void Bind(string regionid)
{
DeviceSystem devicesys = new DeviceSystem();
string message;
List<Device> devicelist = devicesys.GetDeviceList(u.sessionid, u.nasid.ToString(), out message);
List<Device> devices = new List<Device>();
foreach (Device item in devicelist)
{
if (item.regionid.ToString() == regionid)
{
devices.Add(item);
}
}
GridView1.DataSource = devices;
GridView1.DataBind();
}