Dev GridView-Bind Detail Grid during runtime

简介: Here is a simple example.ASPX function OnGetSelectedFieldValues(selectedValues) ...

Here is a simple example.

ASPX

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Test._Default" %>

<%@ Register Assembly="DevExpress.Web.v12.2, Version=12.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>

<%@ Register Assembly="DevExpress.Web.v12.2, Version=12.2.7.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form" runat="server">
        <script language="javascript" type="text/javascript">
            function OnGetSelectedFieldValues(selectedValues) {
                alert(selectedValues);
            }
        </script>
        <dx:ASPxGridView ID="grid" ClientInstanceName="grid" runat="server" DataSourceID="masterDataSource"
            KeyFieldName="ID" Width="100%">
            <Columns>
                <dx:GridViewDataColumn FieldName="Name" Caption="名称" />
            </Columns>
            <Templates>
                <DetailRow>
                    <dx:ASPxGridView ID="detailGrid" runat="server" KeyFieldName="ID"
                        Width="100%" ClientInstanceName="dgdv" OnInit="detailGrid_Init">
                        <Columns>
                            <dx:GridViewCommandColumn ShowSelectCheckbox="True">
                                <HeaderTemplate>
                                    <dx:ASPxCheckBox ID="SelectAllCheckBox" runat="server" ToolTip="Select/Unselect all rows on the page"
                                        ClientSideEvents-CheckedChanged="function(s, e) { dgdv.SelectAllRowsOnPage(s.GetChecked()); }" />
                                </HeaderTemplate>
                                <HeaderStyle HorizontalAlign="Center" />
                            </dx:GridViewCommandColumn>
                            <dx:GridViewDataColumn FieldName="Name" Caption="名称" />
                        </Columns>
                        <SettingsBehavior AllowSelectByRowClick="true" />
                    </dx:ASPxGridView>
                </DetailRow>
            </Templates>
            <SettingsDetail ShowDetailRow="true" AllowOnlyOneMasterRowExpanded="true" />
        </dx:ASPxGridView>
        <dx:ASPxButton ID="btnTest" runat="server" Text="Test">
            <ClientSideEvents Click="function(s, e){
                    dgdv.GetSelectedFieldValues('ID', OnGetSelectedFieldValues);
                    e.processOnServer = false;
                }" />
        </dx:ASPxButton>
        <asp:SqlDataSource
            ID="masterDataSource"
            runat="server"
            DataSourceMode="DataReader"
            ConnectionString="<%$ ConnectionStrings:TestConn%>"
            SelectCommand="SELECT * FROM Line"></asp:SqlDataSource>
    </form>
</body>
</html>


CS

using DevExpress.Web.ASPxEditors;
using DevExpress.Web.ASPxGridView;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Test
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void detailGrid_Init(object sender, EventArgs e)
        {
            ASPxGridView dgrid = sender as ASPxGridView;
            if (dgrid == null) return;

            var dataFileId = (int)(sender as ASPxGridView).GetMasterRowFieldValues("ID");
            DataTable table = new DataTable();
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["TestConn"].ConnectionString);
            conn.Open();
            SqlCommand cmd = conn.CreateCommand();
            cmd.CommandText = string.Format("select * from Main where LineID={0}", dataFileId);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            sda.Fill(table);
            conn.Close();
            dgrid.DataSource = table;
            dgrid.DataBind();
        }
    }
}

 

相关文章
Unknown custom element: <add-employee> - did you register the component correctly? For red cursive c
原因: 1.组件名没写对(导入和注册不对应) 2.components少写了个s 3.组件命名最好是驼峰命名 4.导入时语法错误 5.代码中有两个components,后一个的值把前一个覆盖了 6.组件直接循环套用了
101 0
|
JavaScript
Element UI报错:Unknown custom element: <el-menu>
Element UI报错:Unknown custom element: <el-menu>
172 0
Extraneous children found when component already has explicitly named default slot. These children
Extraneous children found when component already has explicitly named default slot. These children
1282 5