PDA

View Full Version : Using the value of a Dropdownlist for 'bind' in a form


snow
06-29-2006, 03:52 PM
Hello,

I was wondering about the possibility of using the value of my DropDownList and not the text as the value that interacts with the datasource.

Athe moment I have something like:

<asp:formview id='formview1' runat='server' DataSourceID='SqlDataSource1' DefaultMode='Insert'>

<asp:dropdownlist id='developerList' runat='server' dataSourceId='SqlDevelopers' dataTextField='name' dataValueField='developerId' text='<%# Bind("developer") %>' >
</asp:dropdownlist>

</asp:formview>

So basically, I want the user to see the developer's name in the box, but behind, for everything to be using the developerID contained in value.

What I'd ideally like is a "value" attribute instead of the "text" attribute - but is there any sensible way to make this work?


Thanks very much,
Sarah Williamson

snow
06-30-2006, 11:35 AM
I found the solution, it was just like I wanted - 'SelectedValue'! (Although I really did look a lot for it before posting here!)

But I'm now having problems with one of the dropdown lists I'm using it with. The particular component in question is being populated from another datasource programatically (it's dynamically linked to another dropdown). It says that "bind() can only be used in the context of a databound control".

Does this mean that I'll have to put in the SelectedValue = <% ((sqldatasource1)) Bind("pes") %> programatically too? & if so, how would I go about that?

Thanks for any help!

Sarah Williamson

snow
07-04-2006, 11:22 AM
I found the solution on a very helpful site that showed how to have my elements databound twice:

http://www.webswapp.com/CodeSamples/aspnet20/dependentlists/default.aspx


I just don't understand why ASP.net won't let me do it automatically - it seems a pretty run-of-the-mill thing!