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>
<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
目前维护的开源产品:https://gitee.com/475660