ASPxGridView控件常用示例五:显示Detail数据

本示例主要演示如何利用两个 ASPxGridView控件来显示主从数据。

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
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

1
2
3
4
5
6
7
8
9
10
11
12
13
Protected Sub Page_Load( ByVal sender  As Object ByVal 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 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<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>

结果如下:

ASPxGridView控件常用示例五:显示Detail数据

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值