asp2.0中formview+dropdown控件小DEMO
来源:互联网 发布:淘宝所有类目 编辑:程序博客网 时间:2024/04/28 22:35
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>
<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>
- asp2.0中formview+dropdown控件小DEMO
- asp2.0中formview+dropdown控件小DEMO
- ASP2.0 自定义控件SKIN的应用
- FormView控件
- UGUI 中Dropdown控件的使用经验
- 网页中控件绑定数据源小demo
- ASP2.0中实现无刷新界面功能
- ASP2.0中基于ICallbackEventHandler的回调机制
- ASP2.0-FreeTextBox使用
- ASP2.0注册IIS
- ASP2
- asp2
- 自定义表格控件 FormView
- Ajax控件之DropDown
- VS中MFC图表控件teechart使用的小Demo
- 用ASP.NET2.0FormView控件控制显示
- 自定义组合控件小demo
- Asp2.0下Login.Aspx页面和VS2005登陆控件冲突问题
- (转)走近VMWare的三种工作模式
- 24的两个好的中文论坛
- magicajax 0.3出来了
- (转载)关于使用CSS居中(包括水平/垂直)
- (转载)缺陷跟踪系统Mantis在Windows下的安装配置
- asp2.0中formview+dropdown控件小DEMO
- magicajax中的中文提示问题
- 推荐个关于 team system教学的好站点
- asp.net 2.0下的petshop出来了
- 终于收到了head first design pattern了
- asp.net 2.0中新增的AppendDataBoundItems
- asp.net 2.0中新增的web.config的默认namespace功能
- Visual Studio 2005 Code Snippets
- vs.net 2005中web.config智能感知丢失时