使用 jQuery 选项卡掌握详细信息
我正在尝试使用 jQuery 选项卡实现主详细信息解决方案。 两个选项卡,第一个选项卡包含 Northwind 客户,选择客户命令应显示选项卡 2 以及该客户的订单。
到目前为止,我得出的结论是,如果不使用某种 Ajax 就无法完成此任务。 我说得对吗?
我从 Matt Matt Berseth 那里得到了一些指示。
有谁可以分享如何实现此目的的任何想法或示例吗?
我认为一种方法是在 GridView1 的 LinkButton 的客户端单击事件中传递 CustomerId,然后聚焦Tab2 并以某种方式通过 JavaScript 加载详细信息网格。 我不太擅长Javascript,所以我被困在这里。
建议和示例代码将非常有帮助。
谢谢
<div id="tabs">
<ul>
<li><a href="#tabs-1">Customers</a></li>
<li><a href="#tabs-2">Orders</a></li>
</ul>
<div id="tabs-1">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="CustomerID"
DataSourceID="SqlDataSource1" PageSize="20">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbtnSelect" runat="server"
Text="Select Link" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True"
SortExpression="CustomerID" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName"
SortExpression="CompanyName" />
<asp:BoundField DataField="Region" HeaderText="Region"
SortExpression="Region" />
<asp:BoundField DataField="PostalCode" HeaderText="PostalCode"
SortExpression="PostalCode" />
</Columns>
</asp:GridView>
</div>
<div id="tabs-2">
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="OrderID" DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="OrderID" HeaderText="OrderID" InsertVisible="False"
ReadOnly="True" SortExpression="OrderID" />
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID"
SortExpression="CustomerID" />
<asp:BoundField DataField="OrderDate" HeaderText="OrderDate"
SortExpression="OrderDate" />
</Columns>
</asp:GridView>
</div>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CustomerID], [CompanyName], [Region], [PostalCode]
FROM [Customers]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [OrderID], [CustomerID], [OrderDate]
FROM [Orders] WHERE ([CustomerID] = @CustomerID)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="CustomerID"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
I am trying to implement a master details solution using the jQuery Tabs. Two tabs, first tab contains Northwind Customers, selecting customer command should display tab2 with the orders for the customer.
So far, I have come to the conclusion that it cannot be done without using some sort of Ajax. Am I correct?
I got some pointers from Matt, Matt Berseth.
Does anyone have any idea or samples they can share on how to accomplish this?
I am thinking that one way of doing it is to pass the CustomerId in the Client Click event of the LinkButton of GridView1 and then focus Tab2 and somehow load the details grid via javascript. I am not too good with Javascript, so I am stuck here.
Suggestions and sample code will be very helpful.
Thanks
<div id="tabs">
<ul>
<li><a href="#tabs-1">Customers</a></li>
<li><a href="#tabs-2">Orders</a></li>
</ul>
<div id="tabs-1">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataKeyNames="CustomerID"
DataSourceID="SqlDataSource1" PageSize="20">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lbtnSelect" runat="server"
Text="Select Link" />
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True"
SortExpression="CustomerID" />
<asp:BoundField DataField="CompanyName" HeaderText="CompanyName"
SortExpression="CompanyName" />
<asp:BoundField DataField="Region" HeaderText="Region"
SortExpression="Region" />
<asp:BoundField DataField="PostalCode" HeaderText="PostalCode"
SortExpression="PostalCode" />
</Columns>
</asp:GridView>
</div>
<div id="tabs-2">
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="OrderID" DataSourceID="SqlDataSource2">
<Columns>
<asp:BoundField DataField="OrderID" HeaderText="OrderID" InsertVisible="False"
ReadOnly="True" SortExpression="OrderID" />
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID"
SortExpression="CustomerID" />
<asp:BoundField DataField="OrderDate" HeaderText="OrderDate"
SortExpression="OrderDate" />
</Columns>
</asp:GridView>
</div>
</div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CustomerID], [CompanyName], [Region], [PostalCode]
FROM [Customers]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [OrderID], [CustomerID], [OrderDate]
FROM [Orders] WHERE ([CustomerID] = @CustomerID)">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="CustomerID"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它绝对可以使用 jQuery 和 AJAX 实现,并且可能非常好,这将需要一些重要的工作,因为您不能真正使用 GridView(除非您使用 UpdatePanel)。 您可以做的是在回发后设置选定的选项卡。 如果您有兴趣执行 jquery AJAX 路由,选项卡控件上有一个选项
或
发表评论,我可以提供示例。 您可以使用 WCF 服务访问您的订单详细信息吗?
示例代码
我刚刚完成了一些基于此的示例代码,我将其上传到我的 MS Live SkyDrive。 您将需要 WCF REST 入门工具包。 jQuery-AjaxTabsView-Sample.zip
博客文章
我还撰写了描述该示例的博客文章。 谢谢你的主意。 http:// /bendewey.wordpress.com/2009/02/04/jquery-tab-view-using-ajax-and-wcf-rest-service/
Its definately doable using jQuery and AJAX and could be very nice, it will take some significant work, since you can't really use the GridView (unless you use an UpdatePanel). What you can do is set the selected tab after postback. There is an option on the tab control
or
Post a comment if your interested in doing the jquery AJAX route, I can provide a sample. Can you use a WCF Service to access your order details?
Sample Code
I just finished some sample code based for this I uploaded it to my MS Live SkyDrive. You will need the WCF REST Starter Kit. jQuery-AjaxTabsView-Sample.zip
Blog Post
I also wrote blog post describing the sample. Thanks for the idea. http://bendewey.wordpress.com/2009/02/04/jquery-tab-view-using-ajax-and-wcf-rest-service/
您将需要 AJAX,因为 JQuery 选项卡不会回发到服务器。 如果您想要回发的选项卡式行为,则相当容易 手动实施,或者您可以为此下载各种预构建的控件。
如果有特殊原因想要使用 JQuery 选项卡,这里是一个示例与 AJAX 片段一起使用。 您可能需要连接主列表中网格的单击事件,以将 ajax 内容加载到第二个选项卡中,并作为 ajax 回调的一部分自动切换到该选项卡。
You'll need AJAX since the JQuery tabs don't post back to the server. If you want tabbed behaviour that does post back, its fairly easy to implement manually, or you can download a wide assortment of pre-built controls for this.
If there is a particular reason to want to use the JQuery tabs, here is an example of it being used with AJAX fragments. You'll probably want to wire up your click events from the grid in your master list to both load the ajax content into the 2nd tab, as well as switch to the tab automatically as part of the ajax callback.