By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,827 Members | 2,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,827 IT Pros & Developers. It's quick & easy.

Substitue ItemArray with something else in a FormView

P: n/a
When loading a FormView I try to fill a third-party combo control with
this code:

Protected Sub FormView1_ItemCreated(ByVal sender As Object, ByVal e As
EventArgs)

If FormView1.Row.RowState = DataControlRowState.Edit Then
Dim rowView As DataRowView = TryCast(FormView1.DataItem,
DataRowView)
If Not rowView Is Nothing Then
'Get and fill cboProject
Dim strProjectID As String =
TryCast(rowView.Row.ItemArray(8), String)
Dim cboProject As WebCombo =
TryCast(FormView1.FindControl("cboProject"), WebCombo)
cboProject.Value = strProjectID
End If
End If

End Sub

It works great except that I would like to change
"TryCast(rowView.Row.ItemArray(8), String)" and use the column name
instead of ItemArray(8). I have many columns in the FormView so it's
very difficult for me to guess which number represents a certain
column.

How can this be done?

I'm very grateful for help!

// S
Jan 20 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi there,

First of all it's better to move databound-releated code to DataBound event
handler. Second you can access column by names directly from DataRowView:

protected Sub FormView1_DataBound( _
ByVal sender As Object, _
ByVal e As EventArgs)

dim formView as FormView = DirectCast(sender, FormView)

if formView.CurrentMode = FormViewMode.Edit then

Dim rowView As DataRowView = TryCast( _
formView.DataItem, DataRowView)
Dim cboProject as WebCombo = TryCast( _
formView.FindControl("cboProject"), WebControl)

cboProject.Value = Convert.ToString(rowView("ColumnName"))

end if

end sub

Hope this helps
--
Milosz
"st****@gmail.com" wrote:
When loading a FormView I try to fill a third-party combo control with
this code:

Protected Sub FormView1_ItemCreated(ByVal sender As Object, ByVal e As
EventArgs)

If FormView1.Row.RowState = DataControlRowState.Edit Then
Dim rowView As DataRowView = TryCast(FormView1.DataItem,
DataRowView)
If Not rowView Is Nothing Then
'Get and fill cboProject
Dim strProjectID As String =
TryCast(rowView.Row.ItemArray(8), String)
Dim cboProject As WebCombo =
TryCast(FormView1.FindControl("cboProject"), WebCombo)
cboProject.Value = strProjectID
End If
End If

End Sub

It works great except that I would like to change
"TryCast(rowView.Row.ItemArray(8), String)" and use the column name
instead of ItemArray(8). I have many columns in the FormView so it's
very difficult for me to guess which number represents a certain
column.

How can this be done?

I'm very grateful for help!

// S
Jan 20 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.