473,732 Members | 2,196 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET 2.0: Bind ArrayList to FormView Control

Hello,

I am trying to bind an arraylist to a FormView DropDownList control in the
PreRender state. The error that I get is the following:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in
the context of a databound control. Any help with this would be
appreciated.
--
Thanks in advance,

sck10
ASP.NET file
--------------
<td style="width:70 %; text-align:left;">
<asp:DropDownLi st id="ddlRevenueY earInsert" Runat="Server"
SelectedValue=' <%# Bind("RevenueYe ar") %>'/></td>
</tr>

CodeBehind File
-----------------
Protected Sub fvCustRev_PreRe nder(ByVal sender As Object, ByVal e As
EventArgs) Handles fvCustRev.PreRe nder
If Me.fvCustRev.Cu rrentMode = FormViewMode.Ed it Then
Me.hdnPresentMo de.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(ctrF or)
Next
arrFor.TrimToSi ze()
'Assign list to FormView datacontrol
If Me.hdnPresentMo de.Value = "fvCustRev.Edit " Then
CType(Me.fvCust Rev.FindControl ("ddlRevenueYea rEdit"),
DropDownList).D ataSource = arrFor
CType(Me.fvCust Rev.FindControl ("ddlRevenueYea rEdit"),
DropDownList).D ataBind()
End If

End Sub
Apr 27 '06 #1
3 3159
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.)

Apr 28 '06 #2
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
(<EditItemTempl ate>) is at the bottom.

CodeBehind File
-----------------
Protected Sub fvCustRev_PreRe nder(ByVal sender As Object, ByVal e As
EventArgs) Handles fvCustRev.PreRe nder
If Me.fvCustRev.Cu rrentMode = FormViewMode.Ed it Then
Me.hdnPresentMo de.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(ctrF or)
Next
arrFor.TrimToSi ze()
'Assign list to FormView datacontrol
If Me.hdnPresentMo de.Value = "fvCustRev.Edit " Then
CType(Me.fvCust Rev.FindControl ("ddlRevenueYea rEdit"),
DropDownList).D ataSource = arrFor
CType(Me.fvCust Rev.FindControl ("ddlRevenueYea rEdit"),
DropDownList).D ataBind()
End If

End Sub
Here is the FormView for the <EditTemplate >
-----------------------------------------------
<asp:FormView
ID="fvCustRev"
runat="server"
DataKeyNames="C ustomerRevenue_ ID"
DataSourceID="d sDetail"
OnItemUpdating= "fvCustRev_Item Updating_Valida te"
OnItemUpdated=" fvCustRev_ItemU pdated_Trans"
OnItemInserting ="fvCustRev_Ite mInserting_Vali date"
DefaultMode="Ed it"
style="width:70 %">

<EditItemTempla te>
<table class="tblOutli ne" style="width:10 0%" border="1px">
<tr>
<th colspan="2"><as p:Label ID="lblTitleEdi t" Text="Customer Revenue:
Edit" runat="server" /></th>
</tr>

<tr>
<td style="width:30 %; text-align:right;" class="BlkB">Re venue
Year:&nbsp;</td>
<td style="width:70 %; text-align:left;">
<asp:DropDownLi st id="ddlRevenueY earEdit" Runat="Server"
DataTextField=" CategoryType_ID " DataValueField= "CategoryType_I D"
SelectedValue=' <%# Bind("RevenueYe ar") %>'/></td>
</tr>

<tr>
<td style="width:30 %; text-align:right;"
class="BlkB">Cu stomer:&nbsp;</td>
<td style="width:70 %; text-align:left;">
<asp:TextBox ID="txtCustomer Edit" Text='<%# Bind("Customer" ) %>'
Width="200px" runat="server" /></td>
</tr>

<tr>
<td style="width:30 %; text-align:right;" class="BlkB">Re gion:&nbsp;</td>
<td style="width:70 %; text-align:left;">
<asp:DropDownLi st id="ddlRegionEd it" DataSourceID="d sRegionDLL"
Runat="Server"
DataTextField=" CategoryType_ID " DataValueField= "CategoryType_I D"
SelectedValue=' <%# Bind("Region") %>'/></td>
</tr>

<tr>
<td style="width:30 %; text-align:right;" class="BlkB">An nual
Rev:&nbsp;</td>
<td style="width:70 %; text-align:left;">
<asp:TextBox ID="txtAnnualRe venueEdit" Text='<%# Bind("AnnualRev enue",
"{0:c0}") %>' Width="100px" runat="server" /></td>
</tr>

<tr>
<td colspan="2">
<br />
&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;
<asp:LinkButt on ID="UpdateButto n" runat="server"
CausesValidatio n="True" CommandName="Up date" Text="Update" />
&nbsp;&nbsp;&nb sp;&nbsp;&nbsp;
<asp:LinkButt on ID="UpdateCance lButton" runat="server"
CausesValidatio n="False" CommandName="Ca ncel" Text="Cancel" /></td>
</tr>

</table><br />
</EditItemTemplat e>


"Steven Cheng[MSFT]" <st*****@online .microsoft.com> wrote in message
news:cx******** ******@TK2MSFTN GXA01.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.)

Apr 28 '06 #3
Thanks for your response Sck10,

From the further code snippet, I've got the things you want to do. So you
just want to use the ArrayList to populate the DropDownList in the
EditTemplate of the FormView control ,correct? If so, I think you can just
use the event of the DropDownList itself(instead of using FormView's event)
to perform the databinding. For example, you can use the DropDownList's
Init event to populate the list items. e.g:

=========aspx== ==========
<asp:FormView ID="FormView1" runat="server" DataKeyNames="P roductID"
DataSourceID="S qlDataSource1">
<EditItemTempla te>
............... ..............
<asp:DropDownLi st ID="DropDownLis t1" runat="server"
OnInit="DropDow nList1_Init">
</asp:DropDownLis t><br />
............... ............... ....
</EditItemTemplat e>

==========code behind========= ======
protected void DropDownList1_I nit(object sender, EventArgs e)
{
DropDownList list = sender as DropDownList;

//replace below with your arrayList code here...

list.DataTextFi eld = "CategoryNa me";
list.DataValueF ield = "CategoryID ";
list.DataSource =
SqlDataSource2. Select(DataSour ceSelectArgumen ts.Empty);
list.DataBind() ;
}
=============== =========

Hope this helps.

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.)
May 1 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1278
by: TdarTdar | last post by:
I wanted to add three columns up on the form and run some logic to fill in the third but not sure how to call the field names in the formview control. Dim Girth As Integer Elenght = (Me.FormView1.lengthTextBox.text * 2) this shows an error of couse, what is the new correct way to do this using MS formview data control?
3
3289
by: serge calderara | last post by:
Dear all, Does anyone know how to bind a System.Collection.ArraysList object to a Dataset ? Thanks for your reply Regards Serge
0
1922
by: moi | last post by:
Hello, With ASP.NET 2 , i have two dropdownlist, one "A" (not in a formview) in the web page and other one "B" in a Insert Template in a formview. There's a link (parameter between this two dropdownlist. When i selected a new item in the A dropdownlist, i have this error message : Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control" when i disable EnableStateView for the formview,...
5
2191
by: Jurgen Appelo | last post by:
I'm at a loss here... My FormView control automatically performs a databind at each postback on the server. But in some cases I don't want this to happen. Like when the business layer decides that some of the information in the controls cannot be accepted. But then the FormView binds to the datasource again, and the input in all contols is lost. And the user will have to type it all over again. In ASP.NET 1.1 we could simply say: If Not...
4
4693
by: J055 | last post by:
Hi I have 2 update buttons in my FormView ('Apply' and 'OK'). I want both buttons to update the data source but the 'OK' button should redirect afterwards. I can see which button is clicked in the ItemCommand event but I can't redirect from here because the ItemUpdated event hasn't fired yet. I can put a variable in the code-behind class which is gets the
3
3192
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; I have a Repeater control where in my code-behind I call: rptrProducts.DataSource = cart.CartItems; rptrProducts.DataBind(); And then in the aspx file I have: <asp:TextBox ID="txtQuantity" Text='<%# Eval("Quantity") %>' runat="server" Columns="3" />
2
5110
by: darren.murray2 | last post by:
Hello all, I'm fairly new at this so I may be doing this the wrong way but I've got a FormView within a multiview that when it is updated in edit mode, will call on the update method associated with the objectdatasource that fills the formview. Problem: One of the fields is a textbox that when clicked has to open up a popup window with a listbox and when that popup closes, it sends the
3
2384
by: sudhashekhar30 | last post by:
hi all i am using formview control(asp.net 2.0) 1rst time. don't know much about it. i want to display record in it from different tables at different time. like 1rst time form view is showing record of tableEmp. 2nd time same formview showing record of tableSalary.i am using c# coding. is it possible to bind data from code behind file? if possible, how? i would also like to know how i can bind formview from datagrid(select event) thanks....
0
1241
by: pbd22 | last post by:
Hi. I am returning to an old bit of code in our program and need to figure out how to sort my columns on bind. I am sorting on Date (mostly) and some other values. Problem is, the code is an ArrayList that seems to do some tricky stuff with a chache object and I am unable to get any sort of sorting happening.
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8774
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9447
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9307
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9181
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2180
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.