Hi Steven,
Actually, I am creating the ArrayList in the CodeBehind and then trying to
bind the FormView Control to it. The ASPX text for the FormView
(<EditItemTemplate>) is at the bottom.
CodeBehind File
-----------------
Protected Sub fvCustRev_PreRender(ByVal sender As Object, ByVal e As
EventArgs) Handles fvCustRev.PreRender
If Me.fvCustRev.CurrentMode = FormViewMode.Edit Then
Me.hdnPresentMode.Value = "fvCustRev.Edit"
Call Me.YearLoop()
End If
End Sub
Private Sub YearLoop()
'Use Array to build DropDownList with For Loop
ctrFor = 0
Dim arrFor As ArrayList = New ArrayList()
For ctrFor = Year(Now()) - 3 To Year(Now()) + 10
arrFor.Add(ctrFor)
Next
arrFor.TrimToSize()
'Assign list to FormView datacontrol
If Me.hdnPresentMode.Value = "fvCustRev.Edit" Then
CType(Me.fvCustRev.FindControl("ddlRevenueYearEdit "),
DropDownList).DataSource = arrFor
CType(Me.fvCustRev.FindControl("ddlRevenueYearEdit "),
DropDownList).DataBind()
End If
End Sub
Here is the FormView for the <EditTemplate>
-----------------------------------------------
<asp:FormView
ID="fvCustRev"
runat="server"
DataKeyNames="CustomerRevenue_ID"
DataSourceID="dsDetail"
OnItemUpdating="fvCustRev_ItemUpdating_Validate"
OnItemUpdated="fvCustRev_ItemUpdated_Trans"
OnItemInserting="fvCustRev_ItemInserting_Validate"
DefaultMode="Edit"
style="width:70%">
<EditItemTemplate>
<table class="tblOutline" style="width:100%" border="1px">
<tr>
<th colspan="2"><asp:Label ID="lblTitleEdit" Text="Customer Revenue:
Edit" runat="server" /></th>
</tr>
<tr>
<td style="width:30%; text-align:right;" class="BlkB">Revenue
Year: </td>
<td style="width:70%; text-align:left;">
<asp:DropDownList id="ddlRevenueYearEdit" Runat="Server"
DataTextField="CategoryType_ID" DataValueField="CategoryType_ID"
SelectedValue='<%# Bind("RevenueYear") %>'/></td>
</tr>
<tr>
<td style="width:30%; text-align:right;"
class="BlkB">Customer: </td>
<td style="width:70%; text-align:left;">
<asp:TextBox ID="txtCustomerEdit" Text='<%# Bind("Customer") %>'
Width="200px" runat="server" /></td>
</tr>
<tr>
<td style="width:30%; text-align:right;" class="BlkB">Region: </td>
<td style="width:70%; text-align:left;">
<asp:DropDownList id="ddlRegionEdit" DataSourceID="dsRegionDLL"
Runat="Server"
DataTextField="CategoryType_ID" DataValueField="CategoryType_ID"
SelectedValue='<%# Bind("Region") %>'/></td>
</tr>
<tr>
<td style="width:30%; text-align:right;" class="BlkB">Annual
Rev: </td>
<td style="width:70%; text-align:left;">
<asp:TextBox ID="txtAnnualRevenueEdit" Text='<%# Bind("AnnualRevenue",
"{0:c0}") %>' Width="100px" runat="server" /></td>
</tr>
<tr>
<td colspan="2">
<br />
<asp:LinkButton ID="UpdateButton" runat="server"
CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" /></td>
</tr>
</table><br />
</EditItemTemplate>
"Steven Cheng[MSFT]" <st*****@online.microsoft.com> wrote in message
news:cx**************@TK2MSFTNGXA01.phx.gbl...
Hi Sck10,
Thank you for posting.
From your description, you're encountering some exception when try to
dynamically bind an ArrayList to the DropDownList control(in a formview?).
As for the FormView and dropdownlist, would you provide the complete page
markup (aspx) so that we can get the complete view of the two controls and
their relation ship. Also, as for intercept the dropdownlist and perform
further databinding, you can use the FormView's "DataBound" event instead
of PreRender, this event fires after the formview has performed
databinding operation. And I think it is better than the PreRender event.
Regards,
Steven Cheng
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)