DevExpress控件使用交流,DevExpress中国社区 售前咨询
当前位置: 首页 > 开发资源 » 示例代码 » ASPxGridView控件常用示例五:显示Detail数据

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

作者:zhuhm   来源:本站原创   浏览:Loading...次   发布时间:2012-11-14   评论:0条

本示例主要演示如何利用两个 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>


结果如下:

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


本站文章除注明转载外,均为本站原创或翻译
欢迎任何形式的转载,但请务必注明出处,尊重他人劳动成果
转载请注明:文章转载自:DevExpress控件中文网 [http://www.devexpresscn.com/]
本文地址:http://www.devexpresscn.com/Resources/CodeExamples-317.html

评论列表

暂无评论

请谈谈你的看法 请使用IE或者Firefox浏览器,暂不支持Chrome!

昵称 不填则默认为游客评论

DevExpress DXperience DXv2 v12

DevExpress DXperience 下载 download

DevExpress购买、价格、授权

慧都控件网为DevExpress界面控件的中国地区唯一正式授权经销商,正版控件销售公司,授权代理商,经销商及合作伙伴。

电话:400-700-1020
        023-66090381

邮箱:sales@evget.com

>>如何选择正规控件购买渠道