zoukankan      html  css  js  c++  java
  • Linq to sql :LinqDataSource

    <head runat="server">
        <title>Untitled Page</title>
        <style type="text/css">
            body
            {
                font-family: Calibri;
                font-size: small;
            }
            .style1
            {
                margin-bottom: 9px;
            }
        </style>
    </head>
    <body>
        <form id="form1" runat="server">
        <div id="category">
            <p class="style1">
       Pick a cateogyr:
            <asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True"
                    DataSourceID="CategoryDataSource" DataTextField="CategoryName"
                    DataValueField="CategoryID">
            </asp:DropDownList>
            </p>
        </div>
        <div>
       
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
                AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ProductID"
                DataSourceID="LinqDataSource1" BackColor="LightGoldenrodYellow"
                BorderColor="Tan" BorderWidth="1px" CellPadding="2" ForeColor="Black"
                GridLines="None">
                <FooterStyle BackColor="Tan" />
                <Columns>
                    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                    <asp:BoundField DataField="ProductID" HeaderText="ProductID"
                        InsertVisible="False" ReadOnly="True" SortExpression="ProductID" />
                    <asp:BoundField DataField="ProductName" HeaderText="ProductName"
                        SortExpression="ProductName" />
                       
                    <asp:TemplateField HeaderText="Category" SortExpression="Category.CategoryName">
                        <ItemTemplate>
                            <%#Eval("Category.CategoryName") %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:DropDownList ID="DropDownList1" runat="server"
                                DataSourceID="CategoryDataSource" DataTextField="CategoryName"
                                DataValueField="CategoryID" SelectedValue='<%# Bind("CategoryID") %>'>
                            </asp:DropDownList>
                        </EditItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Supplier" SortExpression="Supplier.CompanyName">
                        <ItemTemplate>
                            <%#Eval("Supplier.CompanyName") %>
                        </ItemTemplate>
                        <EditItemTemplate>
                            <asp:DropDownList ID="DropDownList2" runat="server"
                                DataSourceID="SupplierDataSource" DataTextField="CompanyName"
                                DataValueField="SupplierID" SelectedValue='<%# Bind("SupplierID") %>'>
                            </asp:DropDownList>
                            <asp:LinqDataSource ID="SupplierDataSource" runat="server"
                                ContextTypeName="LinkPart5.Data.NorthwindDataContext"
                                Select="new (SupplierID, CompanyName)" TableName="Suppliers">
                            </asp:LinqDataSource>
                        </EditItemTemplate>
                    </asp:TemplateField>
                   
                    <asp:BoundField DataField="UnitsInStock" HeaderText="UnitsInStock"
                   
                        SortExpression="UnitsInStock" />
                    <asp:BoundField DataField="UnitsOnOrder" HeaderText="UnitsOnOrder"
                        SortExpression="UnitsOnOrder" />
                    <asp:BoundField DataField="ReorderLevel" HeaderText="ReorderLevel"
                        SortExpression="ReorderLevel" />
                    <asp:CheckBoxField DataField="Discontinued" HeaderText="Discontinued"
                        SortExpression="Discontinued" />
                </Columns>
                <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue"
                    HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
                <HeaderStyle BackColor="Tan" Font-Bold="True" />
                <AlternatingRowStyle BackColor="PaleGoldenrod" />
            </asp:GridView>
            <asp:LinqDataSource ID="LinqDataSource1" runat="server"
                ContextTypeName="LinkPart5.Data.NorthwindDataContext" EnableDelete="True"
                EnableInsert="True" EnableUpdate="True" TableName="Products"
                Where="CategoryID == @CategoryID">
                <WhereParameters>
                    <asp:ControlParameter ControlID="DropDownList3" Name="CategoryID"
                        PropertyName="SelectedValue" Type="Int32" />
                </WhereParameters>
            </asp:LinqDataSource>
                            <asp:LinqDataSource ID="CategoryDataSource" runat="server"
                                ContextTypeName="LinkPart5.Data.NorthwindDataContext"
                                Select="new (CategoryID, CategoryName)" TableName="Categories">
                            </asp:LinqDataSource>
       
        </div>
        </form>
    </body>
    </html>
    关于作者: 王昕(QQ:475660) 在广州工作生活30余年。十多年开发经验,在Java、即时通讯、NoSQL、BPM、大数据等领域较有经验。
    目前维护的开源产品:https://gitee.com/475660
  • 相关阅读:
    终于以一个ACMer的名义开通博客了。。
    Struts学习笔记一
    Matplotlib画图
    设计模式第一集——策略模式
    Hibernate学习笔记
    在linux下加python path【转】
    linux学习笔记
    C#3.0初体验
    asp.net中使用ffmpeg
    常用的正则表达式(经典)
  • 原文地址:https://www.cnblogs.com/starcrm/p/1362181.html
Copyright © 2011-2022 走看看