423,504 Members | 1,125 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,504 IT Pros & Developers. It's quick & easy.

dropdown binding with datalist value of zero for please select...

P: n/a
hi,,

im trying to work out what code is needed for the below problem about databinding a dropdown list and having actual datalist items as value "0" ie 'please select'

can anyone tell me how to do this in relation to the below code,,

thanks

paul.
>>>>>>>>>


So I'm guessing that this behavior is by design??

I was able to Insert a row after the bind and that works!

Thanks!
Andrea
"bruce barker" <no***********@safeco.com> wrote in message
news:uI**************@tk2msftngp13.phx.gbl...
in the codebehind, add it after the bind

-- bruce (sqlwork.com)
"Andrea Williams" <an*******@hotmail.IHATESpam.com> wrote in message
news:#x**************@TK2MSFTNGP11.phx.gbl...
I have a drop down control that I've added a list item that has a value

of zero and the text name is "[Select One]". And it shows up like it's
supposed to until I bind a dataset to it. The binding seems to remove the list Item that I added. Is there something I have to set to keep the list Item that I added via ASPX code? Has anyone been successful in having a
defuatl selection that is not in the data set?

ASPX code:
<asp:DropDownList id="cboConferenceID" runat="server" AutoPostBack="True"> <asp:ListItem Value="0">[Select One]</asp:ListItem>
</asp:DropDownList>

ASP C# code-behind:
this.cboConferenceID.DataSource = dsGeneric;
this.cboConferenceID.DataTextField = vstrDataTextField;
this.cboConferenceID.DataValueField = vstrDataValueField;
this.cboConferenceID.DataBind();

Thanks in advance,
Andrea

PS: VS.NET 2003 on WIN 2000


---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup engine supports Post Alerts, Ratings, and Searching.
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi paul
I am not sure if i ve got you right but if you want to add an item to the dropdown control then you can use the following cod
Dim lstItem As New ListIte
lstItem.Text = "Please Select
lstItem.Value = "0
DropDownList1.Items.Add(lstItem
regard
srini
Nov 18 '05 #2

P: n/a
Hi

Or create a temp table and insert 0,'Please select' then insert the other
stuff into the table

Something like this ( sql SP )
CREATE Table #ItemsTemp
(
ID int,
sText varchar(255)
)
INSERT #ItemsTemp (ID,sText) VALUES(0,'Please select')
INSERT #ItemsTemp SELECT ID,sText FROM MYTABLE ORDER By sText

SELECT ID,sText FROM #ItemsTemp

Not tested but should do the trick...

--
Best Regards
Vidar Petursson
==============================
Microsoft Scripting MVP
http://www.microsoft.com/technet/scriptcenter
==============================
"DotNetJunkies User" <User@-NOSPAM-DotNetJunkies.com> wrote in message
news:O$*************@TK2MSFTNGP09.phx.gbl...
hi,,

im trying to work out what code is needed for the below problem about
databinding a dropdown list and having actual datalist items as value "0"
ie 'please select'

can anyone tell me how to do this in relation to the below code,,

thanks

paul.
>>>>>>>>>>

So I'm guessing that this behavior is by design??

I was able to Insert a row after the bind and that works!

Thanks!
Andrea
"bruce barker" <no***********@safeco.com> wrote in message
news:uI**************@tk2msftngp13.phx.gbl...
in the codebehind, add it after the bind

-- bruce (sqlwork.com)
"Andrea Williams" <an*******@hotmail.IHATESpam.com> wrote in message
news:#x**************@TK2MSFTNGP11.phx.gbl...
> I have a drop down control that I've added a list item that has a value

of > zero and the text name is "[Select One]". And it shows up like it's
> supposed to until I bind a dataset to it. The binding seems to remove the > list Item that I added. Is there something I have to set to keep the list > Item that I added via ASPX code? Has anyone been successful in having a
> defuatl selection that is not in the data set?
>
> ASPX code:
> <asp:DropDownList id="cboConferenceID" runat="server" AutoPostBack="True"> > <asp:ListItem Value="0">[Select One]</asp:ListItem>
> </asp:DropDownList>
>
> ASP C# code-behind:
> this.cboConferenceID.DataSource = dsGeneric;
> this.cboConferenceID.DataTextField = vstrDataTextField;
> this.cboConferenceID.DataValueField = vstrDataValueField;
> this.cboConferenceID.DataBind();
>
> Thanks in advance,
> Andrea
>
> PS: VS.NET 2003 on WIN 2000
>
>


---
Posted using Wimdows.net NntpNews Component -

Post Made from http://www.DotNetJunkies.com/newsgroups Our newsgroup
engine supports Post Alerts, Ratings, and Searching.

Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.