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
  • 相关阅读:
    开始Flask项目
    夜间模式的开启与关闭,父模板的制作
    从首页问答标题到问答详情页
    首页列表显示全部问答,完成问答详情页布局
    制作首页的显示列表
    发布功能完成
    登录之后更新导航
    完成登录功能,用session记住用户名
    完成注册功能
    通过用户模型,对数据库进行增删改查操作
  • 原文地址:https://www.cnblogs.com/starcrm/p/1362181.html
Copyright © 2011-2022 走看看