关于WebUI中WebGrid的层次结构,代码绑定数据

<ISWebGrid:WebGrid ID="WebGrid1" runat="server" Height="250px"
            Width="500px" OnInitializeDataSource="WebGrid1_InitializeDataSource" OnPrepareDataBinding="WebGrid1_PrepareDataBinding">
            <RootTable Caption="Customers" DataMember="Customers" DataKeyField="CustomerID">
                <ChildTables>
                    <ISWebGrid:WebGridTable Caption="Orders" DataKeyField="OrderID" DataMember="Orders">
                        <ChildTables>
                            <ISWebGrid:WebGridTable Caption="Order Details" DataKeyField="OrderID" DataMember="Order Details">
                                <Columns>
                                    <ISWebGrid:WebGridColumn Caption="ProductID" DataMember="ProductID" EditType="NoEdit"
                                        Name="ProductID">
                                    </ISWebGrid:WebGridColumn>
                                </Columns>
                            </ISWebGrid:WebGridTable>
                        </ChildTables>
                        <Columns>
                            <ISWebGrid:WebGridColumn Caption="OrderID" DataMember="OrderID" EditType="NoEdit"
                                Name="OrderID">
                            </ISWebGrid:WebGridColumn>
                            <ISWebGrid:WebGridColumn Bound="False" Caption="操作" ColumnType="Template" EditType="NoEdit"
                                Name="deleteOrder" Width="50px">
                            </ISWebGrid:WebGridColumn>
                        </Columns>
                    </ISWebGrid:WebGridTable>
                </ChildTables>
                <Columns>
                    <ISWebGrid:WebGridColumn Caption="CustomerID" DataMember="CustomerID" EditType="NoEdit"
                        Name="CustomerID" Width="100px">
                    </ISWebGrid:WebGridColumn>
                    <ISWebGrid:WebGridColumn Bound="False" Caption="操作" ColumnType="Template" EditType="NoEdit"
                        Name="deleteProduct" Width="50px">
                    </ISWebGrid:WebGridColumn>
                </Columns>
            </RootTable>
            <LayoutSettings Hierarchical="True" GridLineColor="221, 236, 254" GridLines="Vertical">
                <HeaderStyle Font-Names="Verdana" Font-Size="8pt" ForeColor="Black"
                    Height="20px" BorderColor="#ACA899" BorderStyle="None" BorderWidth="1px" CustomRules="border-bottom: #73A1E4 1px solid" BackgroundImage="/CommonLibrary/Images/ColBk.gif">
                </HeaderStyle>
                <FocusCellStyle BorderColor="0, 45, 150" BorderStyle="Solid" BorderWidth="1px" />
                <StatusBarCommandStyle>
                    <Active BackColor="RoyalBlue" BaseStyle="Over">
                    </Active>
                    <Over BackColor="#FBE9B8" BorderColor="#002D96" BorderStyle="Solid" BorderWidth="1px">
                    </Over>
                    <Normal>
                        <Padding Bottom="1px" Left="1px" Right="1px" Top="1px" />
                    </Normal>
                </StatusBarCommandStyle>
                <GroupRowInfoStyle Font-Names="Verdana" Font-Size="8pt" BorderColor="Black" BorderStyle="None" CustomRules="border-bottom: #73A1E4 1px solid" BackgroundImage="/CommonLibrary/Images/ColBk.gif">
                </GroupRowInfoStyle>
                <GroupByBox>
                    <LabelStyle BackColor="White" BorderColor="Navy" BorderStyle="Solid" BorderWidth="1px"
                        Font-Names="Verdana" Font-Size="8pt" />
                    <Style BackColor="#E1E1EC"></Style>
                </GroupByBox>
                <EditTextboxStyle BorderStyle="None" BorderWidth="0px" Font-Names="Verdana" Font-Size="8pt">
                </EditTextboxStyle>
                <FrameStyle BackColor="#A9C7F4">
                </FrameStyle>
                <SelectedRowStyle BackColor="#FBE9B8" />
                <AlternatingRowStyle BackColor="#DDECFE" CustomRules="text-overflow: ellipsis; overflow-x: hidden"
                    Font-Names="Verdana" Font-Size="8pt" />
                <ImageSettings CollapseImage="MacMin.gif" ExpandImage="MacPlus.gif" ExportImage="MacExport.gif"
                    FilterImage="MacFilter.gif" HelpImage="MacHelp.gif" InProgressImage="WG4_inprogress.gif"
                    MoreDataImage="MacLoadMore.gif" />
                <StatusBarStyle BackColor="#DDECFE" Font-Names="Verdana" Font-Size="8pt" BorderColor="#73A1E4" BorderStyle="Solid" BorderWidth="1px">
                    <Padding Bottom="2px" Left="2px" Right="2px" Top="2px" />
                </StatusBarStyle>
                <RowStyle BackColor="White" CustomRules="text-overflow: ellipsis; overflow-x: hidden"
                    Font-Names="Verdana" Font-Size="8pt" />
                <NewRowStyle BackColor="White" Font-Names="Verdana" Font-Size="8pt" ForeColor="DarkGray">
                </NewRowStyle>
                <EditFocusCellStyle BackColor="#E9CD82">
                </EditFocusCellStyle>
            </LayoutSettings>
        </ISWebGrid:WebGrid>


 

 


public DataSet GetDataSet()
    {
        string oleStr = "Provider=Microsoft.Jet.Oledb.4.0; Data Source=" + Server.MapPath("~/App_Data/NorthWind.mdb");
        DataSet ds = new DataSet();
        string sqlStr1 = "select * from Customers where CustomerID='ALFKI'";
        string sqlStr2 = "select * from Orders where CustomerID ='ALFKI'"; //
        string sqlStr3 = "select * from [Order Details] where OrderID in (select OrderID from Orders where CustomerID ='ALFKI')";// 

        OleDbConnection oleConn = new OleDbConnection(oleStr);
        oleConn.Open();
        OleDbDataAdapter oleAdpt1 = new OleDbDataAdapter(sqlStr1, oleConn);
        OleDbDataAdapter oleAdpt2 = new OleDbDataAdapter(sqlStr2, oleConn);
        OleDbDataAdapter oleAdpt3 = new OleDbDataAdapter(sqlStr3, oleConn);
        oleAdpt1.Fill(ds, "Customers");
        oleAdpt2.Fill(ds, "Orders");
        oleAdpt3.Fill(ds, "Order Details");
        DataColumn DcParent = new DataColumn();
        DataColumn DcChild = new DataColumn();
        DcParent = ds.Tables["Customers"].Columns["CustomerID"];
        DcChild = ds.Tables["Orders"].Columns["CustomerID"];
        DataRelation DrCustomers = new DataRelation("RelationCustomers", DcParent, DcChild);
        ds.Relations.Add(DrCustomers);

        DcParent = ds.Tables["Orders"].Columns["OrderID"];
        DcChild = ds.Tables["Order Details"].Columns["OrderID"];
        DataRelation DrOrders = new DataRelation("RelationOrders", DcParent, DcChild);
        ds.Relations.Add(DrOrders);
        oleConn.Close();
        return ds;
    }

    protected void WebGrid1_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
    {
        DataSet ds = GetDataSet();
        e.DataSource = ds;

    }


 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值