我有一个嵌套的 GridView(GvMP_Summary_Items
),每一行都包含一个 DropDownList。DropDownList 在嵌套 GridView 的 RowDataBound 事件上绑定。
每一行还包含一个按钮。在 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#进行答复,但两者都可以接受。