您好,登錄后才能下訂單哦!
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>
<!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="form1" runat="server">
<div>
<p>控件SqlDataSource與FormViw應用之在插入模板添加控件DropDwonList并保存記錄實例</p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:HRM_DATAConnectionString %>"
SelectCommand="SELECT [CompanyID], [Company] FROM [tblCompany]">
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="CompanyID" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="CompanyID" HeaderText="CompanyID"
InsertVisible="False" ReadOnly="True" SortExpression="CompanyID" />
<asp:BoundField DataField="Company" HeaderText="Company"
SortExpression="Company" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:HRM_DATAConnectionString %>"
InsertCommand="INSERT INTO tblDepart(Depart, CompanyID) VALUES (@Depart,@CompanyID)"
SelectCommand="SELECT tblDepart.DepartID, tblDepart.Depart, tblCompany.Company, tblDepart.CompanyID FROM tblDepart INNER JOIN tblCompany ON tblDepart.CompanyID = tblCompany.CompanyID WHERE (tblCompany.CompanyID = @Companyid)">
<InsertParameters>
<asp:Parameter Name="Depart" />
<asp:Parameter Name="CompanyID" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Companyid"
PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>
<asp:FormView ID="FormView1" runat="server" AllowPaging="True"
BackColor="White" BorderColor="#CC9966" BorderStyle="None" BorderWidth="1px"
CellPadding="4" DataKeyNames="DepartID" DataSourceID="SqlDataSource2"
GridLines="Both" Height="125px" Width="566px">
<EditItemTemplate>
DepartID:
<asp:Label ID="DepartIDLabel1" runat="server" Text='<%# Eval("DepartID") %>' />
<br />
Depart:
<asp:TextBox ID="DepartTextBox" runat="server" Text='<%# Bind("Depart") %>' />
<br />
Company:
<asp:TextBox ID="CompanyTextBox" runat="server" Text='<%# Bind("Company") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="更新" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="取消" />
</EditItemTemplate>
<EditRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="#663399" />
<FooterStyle BackColor="#FFFFCC" ForeColor="#330099" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="#FFFFCC" />
<InsertItemTemplate>
Depart:
<asp:TextBox ID="DepartTextBox" runat="server" Text='<%# Bind("Depart") %>' />
<br />
Company:
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Company"
DataValueField="CompanyID" SelectedValue='<%# Bind("CompanyID") %>'>
</asp:DropDownList>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="插入" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="取消" />
</InsertItemTemplate>
<ItemTemplate>
DepartID:
<asp:Label ID="DepartIDLabel" runat="server" Text='<%# Eval("DepartID") %>' />
<br />
Depart:
<asp:Label ID="DepartLabel" runat="server" Text='<%# Bind("Depart") %>' />
<br />
Company:
<asp:Label ID="CompanyLabel" runat="server" Text='<%# Bind("Company") %>' />
<br />
<br />
<br />
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="New">New</asp:LinkButton>
</ItemTemplate>
<PagerStyle BackColor="#FFFFCC" ForeColor="#330099" HorizontalAlign="Center" />
<RowStyle BackColor="White" ForeColor="#330099" />
</asp:FormView>
<br />
<br />
</div>
</form>
</body>
</html>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。