温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-06-30 02:19:26 来源:网络 阅读:668 作者:chul72 栏目:编程语言

<%@ 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>


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI