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
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