FormView的插入模板中的DropDownList控件参数

<%@ 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="更新" />
                &nbsp;<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="插入" />
                &nbsp;<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>


你可能感兴趣的:(dropdownlist,SqlDataSource,FormView)