<%@ 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键没改变

解决方案 »

  1.   

    你UPDATA了什么?.cs代码呢?!
      

  2.   

    UPdate[Products] SET[UnitPrice] = @UnitPrice WHERE [ProductID] =@ProductIDUPdate_[Products] SET[UnitPrice] = @UnitPrice WHERE [ProductID] =@ProductID空开试试。
      

  3.   

    请问一下你的UPDATE代码在哪里?更新是让人输入了以后才可以更新的,你的连输入的地方都没有,Eval是单向的绑定,要是你换了BIND我想也是没有用的,Repeater是展示数据用的,要是想实现更新的话就用GridView试试。更对的操作见网上。
      

  4.   

    谢谢回答的朋友  确实没有输入的地方
    <asp:Textbox ID="Label1" Text=' <%#Eval("UnitPrice") %>' runat="server" /> 
    即可以实现输入 以及UPDATE功能 
    由于不是C#.NET 所以没有.CS文件  谢谢