我有一个嵌套的GridView(GvMP_Summary_Items).每行包含一个DropDownList.DropDownList以嵌套GridView的RowDataBound事件为界.
每行还包含1个Button.在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
Run Code Online (Sandbox Code Playgroud)
我甚至在GridView行中包含一个TextBox,默认值为空"".虽然在行上输入了某些内容,但是RowCommand事件会在其前面带回逗号(,).
这证明我正在拾取正确的行,并且可以从TextBox但不是DropDownList中检索值.
有什么我想念的吗?为什么我可以返回在TextBox中输入的值而不是DropDownList的选定值?另外为什么逗号(,)在TextBox值前面?
注意:在上面的情况下,代码是用VB编写的,所以在VB中用C#解答,但我可以同时接受这两个.