【发布时间】:2018-06-17 14:28:38
【问题描述】:
我有一个嵌套的 GridView(GvMP_Summary_Items)。每行包含一个 DropDownList。 DropDownList 以嵌套 GridView 的 RowDataBound 事件为界。
每行还包含 1 个按钮。在 RowCommand 事件上按下此按钮后,我想找到 DropDownList 的当前选定值,以便在代码中进一步使用它。
我的代码只会获取每一行的 DropDownList 的默认值,当前每行设置为0。
下面是 RowCommand 事件:
Protected Sub GvMP_Summary_Items_RowCommand(sender As Object, e As GridViewCommandEventArgs)
Dim lb As ImageButton = CType(e.CommandSource, ImageButton)
Dim gvRow As GridViewRow = lb.BindingContainer //Getting current row to get index
Dim GvMP_Summary_Items As GridView = CType(gvRow.FindControl("GvMP_Summary_Items"), GridView)
Dim intMPItem_Qty As Integer = CType(gvRow.FindControl("cboMPItem_Qty"), DropDownList).SelectedValue
Dim strMPItem_Qty As String = CType(gvRow.FindControl("txtMPItem_Qty"), TextBox).Text
End Sub
我什至在 GridView 行中包含了一个 TextBox,其默认值为空 ""。尽管在行上,如果输入了某些内容,on RowCommand 事件会带回前面带有逗号(,)的值。
这证明我选择了正确的行,并且可以从 TextBox 但不能从 DropDownList 中检索值。
我有什么遗漏吗?为什么我可以返回在 TextBox 中输入的值,但不能返回 DropDownList 的选定值?还有为什么 TextBox 值前面的逗号(,)?
注意:在上述情况下,代码是使用 VB 编写的,所以在 VB 中通过 C# 回答,但我可以接受两者。
【问题讨论】:
-
如何填充下拉列表?您是否有可能在每次回发时将其清除并重新填充,并将其重置为默认值?
标签: c# asp.net vb.net gridview nested-gridview