原創(chuàng)|其它|編輯:郝浩|2012-11-14 11:16:32.000|閱讀 1567 次
概述:本示例主要演示如何利用兩個 ASPxGridView控件來顯示主從數據。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
本示例主要演示如何利用兩個 ASPxGridView控件來顯示主從數據。
C#
protected void Page_Load(object sender, EventArgs e) { if (Session["CategoryID"] != null) { detailGrid.DataSource = dsProducts; detailGrid.DataBind(); } } protected void detailGrid_CustomCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs e) { object masterKeyValue = masterGrid.GetRowValues(Convert.ToInt32(e.Parameters), "CategoryID"); Session["CategoryID"] = masterKeyValue; detailGrid.DataSource = dsProducts; detailGrid.PageIndex = 0; detailGrid.DataBind(); }
VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) If Session("CategoryID") IsNot Nothing Then detailGrid.DataSource = dsProducts detailGrid.DataBind() End If End Sub Protected Sub detailGrid_CustomCallback(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs) Dim masterKeyValue As Object = masterGrid.GetRowValues(Convert.ToInt32(e.Parameters), "CategoryID") Session("CategoryID") = masterKeyValue detailGrid.DataSource = dsProducts detailGrid.PageIndex = 0 detailGrid.DataBind() End Sub
Asp
<dxwgv:ASPxGridView ID="masterGrid" runat="server" AutoGenerateColumns="False" DataSourceID="dsCategories" KeyFieldName="CategoryID" Width="550px"> <SettingsBehavior AllowFocusedRow="True" /> <SettingsText Title="Categories" /> <Columns> <dxwgv:GridViewDataTextColumn FieldName="CategoryID" ReadOnly="True" VisibleIndex="0"> <EditFormSettings Visible="False" /> </dxwgv:GridViewDataTextColumn> <dxwgv:GridViewDataTextColumn FieldName="CategoryName" VisibleIndex="1"> </dxwgv:GridViewDataTextColumn> <dxwgv:GridViewDataTextColumn FieldName="Description" VisibleIndex="2"> </dxwgv:GridViewDataTextColumn> </Columns> <Settings ShowTitlePanel="True" /> <ClientSideEvents FocusedRowChanged="function(s, e) { dGrid.PerformCallback(s.GetFocusedRowIndex()); }" /> </dxwgv:ASPxGridView> <br/> <dxwgv:ASPxGridView ID="detailGrid" runat="server" Width="550px" AutoGenerateColumns="False" ClientInstanceName="dGrid" KeyFieldName="ProductID" OnCustomCallback="detailGrid_CustomCallback"> <SettingsText Title="Products" /> <Settings ShowTitlePanel="True" /> <Columns> <dxwgv:GridViewDataTextColumn FieldName="ProductID" ReadOnly="True" Visible="False" VisibleIndex="0"> <EditFormSettings Visible="False" /> </dxwgv:GridViewDataTextColumn> <dxwgv:GridViewDataTextColumn FieldName="ProductName" VisibleIndex="0"> </dxwgv:GridViewDataTextColumn> <dxwgv:GridViewDataTextColumn FieldName="UnitPrice" VisibleIndex="1"> </dxwgv:GridViewDataTextColumn> <dxwgv:GridViewDataTextColumn FieldName="UnitsInStock" VisibleIndex="2"> </dxwgv:GridViewDataTextColumn> <dxwgv:GridViewDataTextColumn FieldName="QuantityPerUnit" VisibleIndex="3"> </dxwgv:GridViewDataTextColumn> <dxwgv:GridViewDataTextColumn FieldName="CategoryID" Visible="False" VisibleIndex="5"> </dxwgv:GridViewDataTextColumn> </Columns> </dxwgv:ASPxGridView> <asp:AccessDataSource ID="dsCategories" runat="server" DataFile="~/App_Data/nwind.mdb" SelectCommand="SELECT [CategoryID], [CategoryName], [Description] FROM [Categories]"> </asp:AccessDataSource> <asp:AccessDataSource ID="dsProducts" runat="server" DataFile="~/App_Data/nwind.mdb" SelectCommand="SELECT [ProductID], [ProductName], [CategoryID], [UnitPrice], [UnitsInStock], [QuantityPerUnit] FROM [Products] WHERE ([CategoryID] = ?)"> <SelectParameters> <asp:SessionParameter Name="CategoryID" SessionField="CategoryID" Type="Int32" /> </SelectParameters> </asp:AccessDataSource>
結果如下:
本站文章除注明轉載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn
文章轉載自:慧都控件網