473,786 Members | 2,428 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using a DropDownList in a FormView with ObjectDataSourc e

Hi

I thought I was trying to do something very simple but I'm have a lot of
trouble trying to do the following.

<asp:FormView ID="fvGroups" runat="server" DataKeyNames="G roupID"
DataSourceID="o dsGroups"
DefaultMode="In sert" Visible="false" OnItemCommand=" fvGroups_ItemCo mmand">
<InsertItemTemp late>
<asp:DropDownLi st ID="ddlEditMode " runat="server"
OnInit="ddlEdit Mode_Init" SelectedValue=' <%# Bind("EditMode" ) %>'>
<asp:ListItem Selected="True" Value="0" Text="Select... " ></asp:ListItem>
</asp:DropDownLis t>
</InsertItemTempl ate>
</asp:FormView>

....

protected void ddlEditMode_Ini t(object sender, EventArgs e)
{
DropDownList ddlEditMode = sender as DropDownList;
ddlEditMode.Ena bleViewState = false;
ddlEditMode.App endDataBoundIte ms = true;
ddlEditMode.Dat aSource = myList; // an OrderedDictiona ry object
ddlEditMode.Dat aTextField = "value";
ddlEditMode.Dat aValueField = "key";
// Bind the data to the control.
ddlEditMode.Dat aBind();
}

When I add SelectedValue=' <%# Bind("EditMode" ) %>'to the DroupDownList I
get this error.

"System.Invalid OperationExcept ion: Databinding methods such as Eval(),
XPath(), and Bind() can only be used in the context of a databound control."

I just want to save the value to the ObjectDataSourc e InsertParameter s.
Surely this is a very standard requirement?

Thanks
Andrew

Sep 14 '06 #1
4 12917
Hi,
In the insert mode you won't need to use <%# Bind("") %because you are
inserting new item so no data to bind to.
all you have to do is to configure the data source to have a control
parameter in its insert parameters that points to the drop down list.

Hope this helps.
Regards,
Mohamed Mosalem


"J055" wrote:
Hi

I thought I was trying to do something very simple but I'm have a lot of
trouble trying to do the following.

<asp:FormView ID="fvGroups" runat="server" DataKeyNames="G roupID"
DataSourceID="o dsGroups"
DefaultMode="In sert" Visible="false" OnItemCommand=" fvGroups_ItemCo mmand">
<InsertItemTemp late>
<asp:DropDownLi st ID="ddlEditMode " runat="server"
OnInit="ddlEdit Mode_Init" SelectedValue=' <%# Bind("EditMode" ) %>'>
<asp:ListItem Selected="True" Value="0" Text="Select... " ></asp:ListItem>
</asp:DropDownLis t>
</InsertItemTempl ate>
</asp:FormView>

....

protected void ddlEditMode_Ini t(object sender, EventArgs e)
{
DropDownList ddlEditMode = sender as DropDownList;
ddlEditMode.Ena bleViewState = false;
ddlEditMode.App endDataBoundIte ms = true;
ddlEditMode.Dat aSource = myList; // an OrderedDictiona ry object
ddlEditMode.Dat aTextField = "value";
ddlEditMode.Dat aValueField = "key";
// Bind the data to the control.
ddlEditMode.Dat aBind();
}

When I add SelectedValue=' <%# Bind("EditMode" ) %>'to the DroupDownList I
get this error.

"System.Invalid OperationExcept ion: Databinding methods such as Eval(),
XPath(), and Bind() can only be used in the context of a databound control."

I just want to save the value to the ObjectDataSourc e InsertParameter s.
Surely this is a very standard requirement?

Thanks
Andrew

Sep 14 '06 #2
Hi Mohamed

I thought a ControlParamete r would work but if I add one to the
ObjectDataSourc e with 'ddlEditMode' as the ControlID I get a 'can't find the
Control' error.

Any ideas?

Thanks
Andrew

"Mohamed Mosalem" <Mo************ @discussions.mi crosoft.comwrot e in
message news:85******** *************** ***********@mic rosoft.com...
Hi,
In the insert mode you won't need to use <%# Bind("") %because you are
inserting new item so no data to bind to.
all you have to do is to configure the data source to have a control
parameter in its insert parameters that points to the drop down list.

Hope this helps.
Regards,
Mohamed Mosalem


"J055" wrote:
>Hi

I thought I was trying to do something very simple but I'm have a lot of
trouble trying to do the following.

<asp:FormVie w ID="fvGroups" runat="server" DataKeyNames="G roupID"
DataSourceID=" odsGroups"
DefaultMode="I nsert" Visible="false"
OnItemCommand= "fvGroups_ItemC ommand">
<InsertItemTem plate>
<asp:DropDownL ist ID="ddlEditMode " runat="server"
OnInit="ddlEdi tMode_Init" SelectedValue=' <%# Bind("EditMode" ) %>'>
<asp:ListIte m Selected="True" Value="0" Text="Select... " ></asp:ListItem>
</asp:DropDownLis t>
</InsertItemTempl ate>
</asp:FormView>

....

protected void ddlEditMode_Ini t(object sender, EventArgs e)
{
DropDownList ddlEditMode = sender as DropDownList;
ddlEditMode.En ableViewState = false;
ddlEditMode.Ap pendDataBoundIt ems = true;
ddlEditMode.Da taSource = myList; // an OrderedDictiona ry object
ddlEditMode.Da taTextField = "value";
ddlEditMode.Da taValueField = "key";
// Bind the data to the control.
ddlEditMode.Da taBind();
}

When I add SelectedValue=' <%# Bind("EditMode" ) %>'to the DroupDownList
I
get this error.

"System.Invali dOperationExcep tion: Databinding methods such as Eval(),
XPath(), and Bind() can only be used in the context of a databound
control."

I just want to save the value to the ObjectDataSourc e InsertParameter s.
Surely this is a very standard requirement?

Thanks
Andrew


Sep 14 '06 #3
Try the following code in the ItemInserting event handler of the form view
protected void fvGroups_ItemIn serting(object sender, FormViewInsertE ventArgs
e)
{

e.Values["EditMode"]=((DropDownList )FormView1.Row. FindControl("dd lEditMode")).Se lectedValue ;
}
"J055" wrote:
Hi Mohamed

I thought a ControlParamete r would work but if I add one to the
ObjectDataSourc e with 'ddlEditMode' as the ControlID I get a 'can't find the
Control' error.

Any ideas?

Thanks
Andrew

"Mohamed Mosalem" <Mo************ @discussions.mi crosoft.comwrot e in
message news:85******** *************** ***********@mic rosoft.com...
Hi,
In the insert mode you won't need to use <%# Bind("") %because you are
inserting new item so no data to bind to.
all you have to do is to configure the data source to have a control
parameter in its insert parameters that points to the drop down list.

Hope this helps.
Regards,
Mohamed Mosalem


"J055" wrote:
Hi

I thought I was trying to do something very simple but I'm have a lot of
trouble trying to do the following.

<asp:FormView ID="fvGroups" runat="server" DataKeyNames="G roupID"
DataSourceID="o dsGroups"
DefaultMode="In sert" Visible="false"
OnItemCommand=" fvGroups_ItemCo mmand">
<InsertItemTemp late>
<asp:DropDownLi st ID="ddlEditMode " runat="server"
OnInit="ddlEdit Mode_Init" SelectedValue=' <%# Bind("EditMode" ) %>'>
<asp:ListItem Selected="True" Value="0" Text="Select... " ></asp:ListItem>
</asp:DropDownLis t>
</InsertItemTempl ate>
</asp:FormView>

....

protected void ddlEditMode_Ini t(object sender, EventArgs e)
{
DropDownList ddlEditMode = sender as DropDownList;
ddlEditMode.Ena bleViewState = false;
ddlEditMode.App endDataBoundIte ms = true;
ddlEditMode.Dat aSource = myList; // an OrderedDictiona ry object
ddlEditMode.Dat aTextField = "value";
ddlEditMode.Dat aValueField = "key";
// Bind the data to the control.
ddlEditMode.Dat aBind();
}

When I add SelectedValue=' <%# Bind("EditMode" ) %>'to the DroupDownList
I
get this error.

"System.Invalid OperationExcept ion: Databinding methods such as Eval(),
XPath(), and Bind() can only be used in the context of a databound
control."

I just want to save the value to the ObjectDataSourc e InsertParameter s.
Surely this is a very standard requirement?

Thanks
Andrew



Sep 14 '06 #4
Hi Andrew,

A control added in an item template will have to be referenced using
FindControl just as Mohamed showed in his code. That's why ObjectDataSourc e
will complain about can't find the control.

I think Mohamed's suggestion will work for you; please let us know your
result so that we can further follow up. Thank you.

Sincerely,
Walter Wang (wa****@online. microsoft.com, remove 'online.')
Microsoft Online Community Support

=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications. If you are using Outlook Express, please make sure you clear the
check box "Tools/Options/Read: Get 300 headers at a time" to see your reply
promptly.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 15 '06 #5

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

Similar topics

0
937
by: FR | last post by:
Hello, I am trying to use a DDL control in the editItemTemplate of a FormView. The DDL has to be populated from a datatable. My problem is that I cannot see the DDL control if this is inside a template. How can I do? Thank you FR
2
6631
by: hooterbite | last post by:
I am using an object datasource to call a stored procedure to update an SQL table. THE STORED PROCEDURE WORKS FINE! THE OBJECTDATASOURCE WORKS FINE! When the textbox is inside a standard HTML tag <table>, it passes the value of the textbox to the stored procedure, as expected. When the textbox is inside an <asp:table> tag, the default value assigned in the FormParameter tag is passed to the stored procedure, as if it can't find the...
1
1177
by: Chris | last post by:
When using the formview control it defaults to the item template and I have to add an edit button to go into the edit template. Is there any way to get it to default to the edit template. It would be nice to able to specify when I open a window with the forview control in whether to display the item or edit template.
1
2769
by: cisco | last post by:
I've been trying to figure out how the client of a DetailsView or FormView should handle the ItemUpdating event when setting the datasource programatically. I want to do something simple like this: formView.DataSource = new SomeUserObject { user }; formView.DataBind(); All the examples i've come across show a declerative data source being used. Do i need to use ObjectDataSource? I can get the information going through the cells by...
0
1145
by: rodchar | last post by:
hey all, i created a typed dataset for my objectdatasource, which in turn will bind to my dropdownlist. in the typed dataset i created an expression column called fullname which is simply FirstName column + LastName column. i can preview the dataset and everything looks normal. however when i bind the objectdatasource to the dropdownlist there's no data. it's like the binding is taking place before the fullname gets populated. any ideas?...
0
1279
by: kidders | last post by:
I have an business object bound to a formview with through an object datasource, in edit mode when i click update i receive the following error: The 'ActionID' property on the type specified by the DataObjectTypeName property in ObjectDataSource 'odsAction' is readonly and its value cannot be set. This is correct as the actionid property is readonly (being the primary key).
0
1331
by: m.bagattini | last post by:
Hello folks, I'll try to be as much clear as I can. This is my issue: Asp.NET 2.0 page w/ FormView (later: FW), an ObjectDataSource (ODS). It works with my Business logic layer, where I have some methods to retrieve and set data. ODS works with this MyObjectManager object. MyObjectManager has GetObjects that return an ObjectsCollection and so on. Nothing special. MyObject has 3 properties, for example: Color, Description, Size...
3
8108
by: KaOne | last post by:
Hi All, excuse me in advance for my not very perfect english. I need some help about a problem with a FormView bounded to an ObjectDataSource. In practise I have an ObjectDataSource that uses some BLL methods that implements the optimistic concurrency by a TimeStamp field into the DB. So, when I execute an insert, update or delete query if I receive 0 like return value from that queries I understand that a concurrency problem is occurs so...
0
1103
by: jphaycock | last post by:
I have a formview that uses an objectdatasource to insert and update records. I don't want to use the objectdatasource's "Delete" method so I have defined this method as "none" in the "configure datasource" wizard. I assumed I could use my own Delete Method by using the ItemCommand: protected void FormViewModule_ItemCommand(object sender, FormViewCommandEventArgs e) {
0
1107
by: Jeff | last post by:
hey asp.net 2.0 I'm getting this error message: DataBinding: 'CarDetail' does not contain a property with the name 'Description'. <asp:DropDownList ID="ddlCarType" DataTextField='<%# Bind("'Description'") %>'
0
9492
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
10360
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
10163
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
9960
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
7510
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
6744
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4064
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3668
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.