Retrieve value from DropDownList in nested GridView on RowCommand

asked8 years ago
last updated8 years ago
viewed2k times
Up Vote15Down Vote

I have a nested GridView(GvMP_Summary_Items). Each row contains a DropDownList. The DropDownList is bounded on the RowDataBound event of the nested GridView.

Each row also contains 1 Button. Upon pressing this button on the RowCommand event, I would like to find the current selected value of the DropDownList so I can use it further on in the code.

The code I have will only get the default value of the DropDownList on each row, which is currently set at 0 for each row.

Below is the RowCommand Event:

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

I have even included a TextBox in the GridView row which default value is empty "". Although on the row if something is entered the on RowCommand event brings back the value with a comma(,) in front of it.

This proves that I am picking up the correct row and can retrieve a value from a TextBox but not a DropDownList.

Is there something I am missing? Why can I return a value entered in a TextBox but not the selected value of a DropDownList? Also why the comma(,) in front of the TextBox value?

In above case code has been written using VB so answers in VB over C# but I can accept both.