【问题标题】:access data in textfied in gridview在gridview的文本字段中访问数据
【发布时间】:2011-06-21 18:44:39
【问题描述】:

我正在处理购物车我有一个 gridview,它循环遍历数据库中的所有记录并显示在 gridview 上我为链接添加了两个额外的列,当用户单击链接时,它将产品添加到购物车中另一列是一个文本字段,用户应该在这里输入他们想要购买的物品的数量是我的问题我可以得到用户在文本字段中输入的值有人可以给我一些指导谢谢


Aspx 页面

<asp:GridView ID="grdProducts" runat="server">

            <Columns>
                <asp:ButtonField CommandName="AddToCart" HeaderText="Add To Cart" Text="Add To Cart" />

              <asp:TemplateField HeaderText="Qty">
            <ItemTemplate>
                <asp:TextBox ID="tbQty" runat="server" Width="25px"
                    MaxLength="3" />
                    </ItemTemplate>
                        <ItemStyle Width="25px" HorizontalAlign="Center"/>
                            </asp:TemplateField>


            </Columns>


        </asp:GridView>

页面背后的代码

 Private Sub grdProducts_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdProducts.RowCommand

        Dim intRowSelected As Integer = -1
        Dim strProductName As String = ""

        Try

            intRowSelected = e.CommandArgument
            strProductName = grdProducts.Rows(e.CommandArgument).Cells(2).Text
            AddItemToCart(strProductName)



            Dim rowIndex As Integer

            If Integer.TryParse(e.CommandArgument.ToString(), rowIndex) Then

                Dim c As Control = grdProducts.Rows(rowIndex).FindControl("tbQty")
                If TypeOf c Is TextBox Then
                    Response.Write(DirectCast(c, TextBox).Text)
                    PlaceHolder1.Controls.Add(c)
                End If
            End If


        Catch ex As Exception
            Debug.WriteLine(ex.Message)
        End Try

    End Sub

如何在 (textfield id =tbQty) 中获取数据

【问题讨论】:

    标签: c# asp.net vb.net


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多