按下按钮时会弹出一个jQuery对话框。我有一个GridView,其中包含我的数据库的结果。我想让GridView显示我搜索过的结果。因此,我添加了asp:textbox
和asp:button
,我的想法是,当我按下按钮时,它将调用与我的数据库连接的函数,然后在GridView中显示结果。所以基本上,当jQuery弹出它应该显示一个空的GridView(或没有)然后当我搜索某些东西时它应该显示结果。
这是我的main.aspx代码:
<div id="ViewPlaces">
<asp:TextBox ID="viewPlaceTextbox" runat="server" placeholder="Search..." />
<asp:Button ID="viewPlaceBtn" OnClick="getSearchedPlace" runat="server" Text="Search for place" />
<asp:GridView ID="GridView1" AllowPaging="true" GridLines="None" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle="alt" runat="server" AllowSorting="True"
AutoGenerateColumns="False"
Width="750px"
CausesValidation="False" ShowHeaderWhenEmpty="true" ShowHeader="true">
<Columns>
<asp:BoundField DataField="place_id" HeaderText="Id" ReadOnly="True" />
<asp:BoundField DataField="place_name" HeaderText="Name" />
<asp:BoundField DataField="place_city" HeaderText="City" />
<asp:BoundField DataField="place_land" HeaderText="Land" />
<asp:BoundField DataField="place_desc" HeaderText="Description" />
</Columns>
</asp:GridView>
</div>
这是jQuery代码:
$('#ViewPlaces').dialog(dialogOpts5);
$.fx.speeds._default = 500;
$(function () {
$("#ViewPlaces").dialog({
autoOpen: false,
show: "blind",
hide: "explode",
});
$("#viewallplaces").click(function () {
$("#ViewPlaces").dialog("open");
return false;
});
});
在我的c#代码中,问题是如果我没有调用该函数来获取Page_Load
中数据库的结果,那么当我按下按钮打开时,GridView就不会被加载jQuery对话框。否则,该函数如下所示:
protected void getPlaces()
{
List<Place> pl = new List<Place>();
pl = functions.getPlaces();
GridView1.DataSource = pl;
GridView1.DataBind();
}
getPlaces()
函数返回一个位置列表。这不是问题,它可以工作,我已经测试过了。
答案 0 :(得分:1)
在这种情况下,您将使用gridforms控件,如gridview和updatepanel以及forego jquery,或者您将使用基本HTML元素并连接jquery来调用端点(url)并呈现结果客户端。但不是两个。
答案 1 :(得分:1)
如果您只在gridview中显示数据,则可以使用单独的页面生成gridview。
想象一下这个页面只保存gridview。您可以使用jquery ajax调用页面传递url中gridview的参数作为查询字符串。然后在gridview页面的页面加载中,您将检查查询字符串参数,然后使用它们在数据库中查询数据,然后使用数据绑定您的gridview。
ajax调用将返回html,你可以将html注入弹出窗口
$.ajax({
url: "yourgridpage.aspx?dat1=YourValue1&dat2=YourVal2"
}).done(data,function() {
$.popUp.html(data);
});