【问题标题】:How to get Textbox data out of a Datagrid如何从 Datagrid 中获取文本框数据
【发布时间】:2013-03-20 19:19:28
【问题描述】:

我有一个文本框,用于在购物车中以数据网格的形式更改数量。当我单击编辑链接按钮时,它允许更改文本框。我想要得到的是更改后的文本,然后替换我的数据表中的原始数量。我尝试了很多不同的东西,但无法让更改后的值保持不变。

这是最终改变数据表的代码:

       For Each objDR In myDataTable.Rows
        If objDR("ItemID") = intItemID Then
            objDR("Quantity") = Int32.Parse(myText) 'adding a specific int like 333 works
            Exit For
        End If
        Next

如前所述,如果我输入一个特定的值,例如“333”,那么数量会发生变化。所以问题必须在于当我点击更新时文本框的值没有被保留,或者至少我是这么看的。

我尝试过的访问文本框文本的代码:

    Dim myText As String
    For Each dataGridItem As DataGridItem In dgCart.Items
        myText = CType(dataGridItem.FindControl("txtQuantity"), TextBox).Text
       'myText = DirectCast(dataGridItem.FindControl("txtQuantity"), TextBox).Text
    Next

    have also tried
    'Dim strQuantity As String = CType(dgCart.Items(0).FindControl("txtQuantity"), TextBox).Text

     'Dim txtQuantity As TextBox = e.Item.FindControl("txtQuantity")

我也尝试过弄乱 txtbox 的视图状态,但这没什么区别。

我该如何解决这个问题?

【问题讨论】:

    标签: asp.net vb.net datagrid textbox


    【解决方案1】:

    不确定您是否想要editCommand 或更新事件。来自 cmets 中的链接:

    Dim tb As TextBox = CType(e.Item.Cells(3).Controls(0), TextBox)
    

    【讨论】:

    • 对不起,我还是个新手。我不太明白你在说什么。在 OnEditCommand 事件中投射对象?
    • 我很抱歉 - 我看到你使用 DataGrid - 在这方面它们非常相似。我只是没有足够的例子来举个例子。
    • 没问题,感谢您的尝试。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-11
    • 2014-12-15
    • 1970-01-01
    • 2012-11-15
    相关资源
    最近更新 更多