<%@ Page Language="VB" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">
Protected Sub Repeater1_Itemcommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs)
If e.CommandName = "update" Then
Dim productID As Label = CType(e.Item.FindControl("lblProductID"), Label)
Dim price As TextBox = CType(e.Item.FindControl("txtPrice"), TextBox)
SqlDataSource1.UpdateParameters("UnitPrice").DefaultValue = CDbl(price.Text)
SqlDataSource1.UpdateParameters("ProductID").DefaultValue = CInt(productID.Text)
SqlDataSource1.Update()
Repeater1.DataBind()
Exit Sub
End If End Sub</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<headertemplate>
<table width="100%" style="font:10pt verdana">
<tr style="background-color:#DFA894">
<th>商品编号</th>
<th>商品名称</th>
<th>商品单价</th>
<th>商品库存</th>
</tr>
</headertemplate>
<ItemTemplate>
<tr style="background-color:#FFECD8">
<td>
<asp:Label ID="lblProductID" Text='<%#Eval("ProductID") %>' runat="server" >
</asp:Label>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem,"ProductName") %>
</td>
<td><asp:Label ID="Label1" Text='<%#Eval("UnitPrice") %>' runat="server" >
</asp:Label></td>
<td>
<%#DataBinder.Eval(Container.DataItem,"UnitsInStock") %>
</td>
<td>
<asp:LinkButton ID="lnkUpdate" CommandName="Update" Text="Update" runat="server"></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductName], [ProductID], [UnitPrice], [UnitsInStock] FROM [Products]" UpdateCommand="UPdate[Products] SET[UnitPrice] = @UnitPrice WHERE [ProductID] =@ProductID">
<UpdateParameters>
<asp:Parameter Name="UnitPrice" />
<asp:Parameter Name="ProductID" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
这是整个程序的代码 但是我运行之后发现无法实现UPDATA操作 点击UPDATA键没改变
Protected Sub Repeater1_Itemcommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs)
If e.CommandName = "update" Then
Dim productID As Label = CType(e.Item.FindControl("lblProductID"), Label)
Dim price As TextBox = CType(e.Item.FindControl("txtPrice"), TextBox)
SqlDataSource1.UpdateParameters("UnitPrice").DefaultValue = CDbl(price.Text)
SqlDataSource1.UpdateParameters("ProductID").DefaultValue = CInt(productID.Text)
SqlDataSource1.Update()
Repeater1.DataBind()
Exit Sub
End If End Sub</script><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
<headertemplate>
<table width="100%" style="font:10pt verdana">
<tr style="background-color:#DFA894">
<th>商品编号</th>
<th>商品名称</th>
<th>商品单价</th>
<th>商品库存</th>
</tr>
</headertemplate>
<ItemTemplate>
<tr style="background-color:#FFECD8">
<td>
<asp:Label ID="lblProductID" Text='<%#Eval("ProductID") %>' runat="server" >
</asp:Label>
</td>
<td>
<%#DataBinder.Eval(Container.DataItem,"ProductName") %>
</td>
<td><asp:Label ID="Label1" Text='<%#Eval("UnitPrice") %>' runat="server" >
</asp:Label></td>
<td>
<%#DataBinder.Eval(Container.DataItem,"UnitsInStock") %>
</td>
<td>
<asp:LinkButton ID="lnkUpdate" CommandName="Update" Text="Update" runat="server"></asp:LinkButton>
</td>
</tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [ProductName], [ProductID], [UnitPrice], [UnitsInStock] FROM [Products]" UpdateCommand="UPdate[Products] SET[UnitPrice] = @UnitPrice WHERE [ProductID] =@ProductID">
<UpdateParameters>
<asp:Parameter Name="UnitPrice" />
<asp:Parameter Name="ProductID" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</form>
</body>
</html>
这是整个程序的代码 但是我运行之后发现无法实现UPDATA操作 点击UPDATA键没改变
解决方案 »
- table网格线为什么老是显不出来,折腾了我好长时间了!在线急等
- 网站即时通讯
- 母版页不能用无刷回调功能?
- QQ群:11262802,这里交流的速度实在太慢!!受不了了!希望各位大侠到QQ群 11262802 一展雄风!!!!
- 用user.identy.name可以读出用户名,怎样读出该用户的全称等域用户信息呢?
- 怎样使"查看头像列表"用鼠标点击的时候将头像下拉表中的选项替换
- 怎样让webform下的checkbox不保存状态
- 去哪下载水晶报表10控件?
- 高分求asp.net+c#编写的留言簿
- 怎样做在浏览器里面播放realplay格式的流媒体
- datalist和formview如何获取控件
- winfrom中SHIFT+TAB键对应的KEYCODE是多少?
<asp:Textbox ID="Label1" Text=' <%#Eval("UnitPrice") %>' runat="server" />
即可以实现输入 以及UPDATE功能
由于不是C#.NET 所以没有.CS文件 谢谢