asp2.0中formview+dropdown控件小DEMO

asp2.0中formview+dropdown控件小DEMO,演示了如何对northwind数据库中的product表进行更改,其中可以对某个产品的所属分类用dropdownlist进行更改,可以注意下formview和dropdownlist的用法
<body>
    <form id="form1" runat="server">
    <div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT [ProductID], [ProductName], [CategoryID] FROM [Products]"
            UpdateCommand="UPDATE  [Products]  SET [ProductName]=@productname,[CategoryID] =@categoryid  WHERE [ProductID] = @productid">
                           <UpdateParameters> 
    <asp:Parameter Name="ProductName" Type="String" />
                       <asp:Parameter Name="CategoryID" Type="Int32" />
                               <asp:Parameter Name="ProductID" Type="Int32" />
                           </UpdateParameters>
        </asp:SqlDataSource>
   
    </div>
        <asp:FormView ID="FormView1" runat="server" AllowPaging="True" DataKeyNames="ProductID"
            DataSourceID="SqlDataSource1">
            <EditItemTemplate>
                ProductID:
                <asp:Label ID="ProductIDLabel1" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label><br />
                ProductName:
                <asp:TextBox ID="ProductNameTextBox" runat="server" Text='<%# Bind("ProductName") %>'>
                </asp:TextBox><br />
                CategoryID:
                <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
                    DataTextField="CategoryName" DataValueField="CategoryID" SelectedValue='<%# Bind("CategoryID") %>'>
                </asp:DropDownList><br />
                 (<asp:Label ID="CategoryIDLabel"                         runat="server"                         Text='<%# Eval("CategoryID") %>' />)<br />
                <asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update"
                    Text="Update">
                </asp:LinkButton>
                <asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="Cancel">
                </asp:LinkButton>
            </EditItemTemplate>
            <InsertItemTemplate>
                ProductName:
                <asp:TextBox ID="ProductNameTextBox" runat="server" Text='<%# Bind("ProductName") %>'>
                </asp:TextBox><br />
                CategoryID:
                <asp:TextBox ID="CategoryIDTextBox" runat="server" Text='<%# Bind("CategoryID") %>'>
                </asp:TextBox><br />
                <asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert"
                    Text="Insert">
                </asp:LinkButton>
                <asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False" CommandName="Cancel"
                    Text="Cancel">
                </asp:LinkButton>
            </InsertItemTemplate>
            <ItemTemplate>
                ProductID:
                <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>'></asp:Label><br />
                ProductName:
                <asp:Label ID="ProductNameLabel" runat="server" Text='<%# Bind("ProductName") %>'></asp:Label><br />
                CategoryID:
               <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="Sqldatasource2"                        DataTextField="CategoryName"                         DataValueField="CategoryID"   SelectedValue='<%# Eval("CategoryID") %>'   Enabled="False" />
                                  (<asp:Label ID="CategoryIDLabel" runat="server"  Text='<%# Eval("CategoryID") %>'/>)
      <asp:LinkButton ID="EditButton" runat="server"   CausesValidation="False"    CommandName="Edit"    Text="Edit" />
            </ItemTemplate>
          
        </asp:FormView>
        <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories]"></asp:SqlDataSource>
    </form>
</body>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值