Author |
Topic |
vk18
Posting Yak Master
146 Posts |
Posted - 2006-10-26 : 19:20:55
|
Hi Friends,there are 5 values in the drop down box that are coming from the database. i want to make 1 value default.how to do this. I am using VB.NET/ASP.NET. Any Ideas..?Thx |
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2006-10-27 : 05:31:58
|
use DropDowwList.selectedValueGo with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp |
 |
|
chiragvm
Yak Posting Veteran
65 Posts |
Posted - 2006-10-27 : 06:34:53
|
dropselect.SelectedIndex (0)here 0 = selected value as integer |
 |
|
vk18
Posting Yak Master
146 Posts |
Posted - 2006-11-02 : 18:14:50
|
quote: Originally posted by spirit1 use DropDowwList.selectedValueGo with the flow & have fun! Else fight the flow blog thingie: http://weblogs.sqlteam.com/mladenp
Hi,I know this property, what i want is I have 5 values in the drop down those are coming from the database.VEGCHEESEBIGSMALLMEDIUMwhen the page loads i want 'VEG' to be displayed as a default valueall the timeThx |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2006-11-02 : 19:30:57
|
After you do the databind to the drop down, try this:ddMyDropDownList.Items.FindByValue("VEG").selected = true You could replace "Veg" with a variable if needed.Hope this Helps!Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights. |
 |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2006-11-02 : 21:16:02
|
you can also say:ddMyDropDownList.SelectedValue = "VEG"- Jeff |
 |
|
vk18
Posting Yak Master
146 Posts |
Posted - 2006-11-03 : 13:32:09
|
quote: Originally posted by MichaelP After you do the databind to the drop down, try this:ddMyDropDownList.Items.FindByValue("VEG").selected = true You could replace "Veg" with a variable if needed.Hope this Helps!Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights.
Hi,I tried this after the DatabindingddMyDropDownList.Items.FindByValue("VEG").selected = trueBut it seems doesn't work.I am getting the messageSpecified argument was out of the range of valid values. Parameter name "VEG"Any Idea..Thx |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2006-11-03 : 15:50:48
|
Is Veg the Value or the Text?Instead of FindByValue try FindByText.Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights. |
 |
|
vk18
Posting Yak Master
146 Posts |
Posted - 2006-11-03 : 16:29:09
|
quote: Originally posted by MichaelP Is Veg the Value or the Text?Instead of FindByValue try FindByText.Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights.
Hi,VEG is the Text, that is coming from a reference table.I tried findbytext still doesn't workThx |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2006-11-03 : 17:04:51
|
How about posting your code so we can see what you are doing. If neither one of those are working, then you must be coding something in the wrong order.Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights. |
 |
|
vk18
Posting Yak Master
146 Posts |
Posted - 2006-11-03 : 18:40:54
|
quote: Originally posted by MichaelP How about posting your code so we can see what you are doing. If neither one of those are working, then you must be coding something in the wrong order.Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights.
Hi,This is the Code i am using.Thx sql = "select pkid,description from tblordertype order by description asc " objDataSet = dbFunctions.GetSQLDataSet(CONNECTIONSTRING, sql) Me.ddOrderType.DataSource = objDataSet.Tables("SQLTable").DefaultView Me.ddOrderType.DataValueField = "pkid" Me.ddOrderType.DataTextField = "description" Me.ddOrderType.DataBind() ''''Me.ddOrderType.Items.FindByText("CASH").Selected = True Me.ddOrderType.Items.Add(New ListItem("", "")) Me.ddOrderType.SelectedValue = "" |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2006-11-05 : 19:27:54
|
Me.ddOrderType.Items.FindByText("CASH").Selected = TrueMake that the last line of your code block.Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights. |
 |
|
vk18
Posting Yak Master
146 Posts |
Posted - 2006-11-06 : 10:43:16
|
quote: Originally posted by MichaelP Me.ddOrderType.Items.FindByText("CASH").Selected = TrueMake that the last line of your code block.MichaelHi,You mean comment the last line of code that i wrote.? I did commented and tried but still the same. Any ideaThx<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights.
|
 |
|
KenW
Constraint Violating Yak Guru
391 Posts |
Posted - 2006-11-06 : 16:06:52
|
quote: Hi,You mean comment the last line of code that i wrote.? I did commented and tried but still the same. Any ideaThx
No. :-) Michael means to move the line to the bottom of the code. sql = "select pkid,description from tblordertype order by description asc "objDataSet = dbFunctions.GetSQLDataSet(CONNECTIONSTRING, sql)Me.ddOrderType.DataSource = objDataSet.Tables("SQLTable").DefaultViewMe.ddOrderType.DataValueField = "pkid"Me.ddOrderType.DataTextField = "description"Me.ddOrderType.DataBind()Me.ddOrderType.Items.Add(New ListItem("", ""))Me.ddOrderType.Items.FindByText("CASH").Selected = True With the code in the order you currently have it, the FindByText() is being cancelled by the addition of the blank item afterward.Ken |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2006-11-06 : 16:47:19
|
Thanks Ken, that's exactly what I meant.You have to do the "Find" last because when you add a new item, it messes up the selected item.Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights. |
 |
|
vk18
Posting Yak Master
146 Posts |
Posted - 2006-11-06 : 17:06:19
|
quote: Originally posted by MichaelP Thanks Ken, that's exactly what I meant.You have to do the "Find" last because when you add a new item, it messes up the selected item.Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights.
Hi Guys,I tried this way also still i am getting this error " Object Reference not set to an instance of object". Any way thx guys for your support. I have to find another way to display this value |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2006-11-06 : 17:10:55
|
Ok, which object is nothing?Test each object to see if it "IS NOTHING"if Me.ddOrderType.Items.FindByText("CASH") is nothing thenthrow new exception("Me.ddOrderType.Items.FindByText(""CASH"") is nothing")end if Do that on each object that may be nothing, and then figure out WHY they are nothing.Michael<Yoda>Use the Search page you must. Find the answer you will. Cursors, path to the Dark Side they are. Avoid them, you must. Use Order By NewID() to get a random record you will.</Yoda>Opinions expressed in this post are not necessarily those of TeleVox Software, inc. All information is provided "AS IS" with no warranties and confers no rights. |
 |
|
|