Selecting a value in a DropDownList

  • Thread starter Bruce Whitehouse
  • Start date
B

Bruce Whitehouse

My datagrid works just fine. I can add and remove elements and it retains
the new values I've entered. The only issue I have is setting the
selectedIndex of the DropDownList that is in my datagrid.

Shown below is a simplified version of my code....
--------------------------------------------------------------
Private Sub setSelectedIndexes(ByVal arrRows As ArrayList)
Dim intCount As Integer

Dim _item As DataGridItem

Dim strSelectedValue As String

For intCount = 0 To dgInvoiceRows.Items.Count - 1

_item = dgInvoiceRows.Items(intCount)

Dim ddlTemp As DropDownList = _item.FindControl("ddlTemp")

strSelectedValue = selectedValues(arrRows, intCount, "Departments")

If Not strSelectedValue Is Nothing Then

ddlTemp.SelectedIndex =
ddlTemp.Items.IndexOf(ddlTemp.Items.FindByValue(strSelectedValue))

End If

Next

End Sub

--------------------------------------------------------------
I can see that within my code it retrieves the specific dropdown from the
datagrid.

I can see that 'strSelectedValue' contains the correct value.

I can even see that
'ddlTemp.Items.IndexOf(ddlTemp.Items.FindByValue(strSelectedValue))' returns
the correct value for the selected index.

The only thing that doesn't happen is set the dropDownList to the
selectedIndex.

Am I meant to re-write the value back to the datagrid, re-bind, or
something?

Or is there a better way of doing this? Should I be setting this from the
web form rather than the code-behind page?



hoping someone can help!

Bruce
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top