Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 26th, 2007, 11:37 PM
Registered User
 
Join Date: Jun 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need Help with DropDownList SelectedValue

Please help me!

I need to get value from dropdownlist when page load and user didn't change any selection.

In the code If Page.IsPostBack is true I got all require information from dropdown list

Is there anyway to get selectedvalue or selecteditem from dropdownlist when page is load I try (Red colour highlight) but not working.

Please help me Thanks so much


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim prmStratID, prmObjID, prmRegID As String

If Page.IsPostBack Then
prmStratID = lstStrategy.SelectedValue.ToString
prmObjID = lstObjective.SelectedValue.ToString
prmRegID = lstRegional.SelectedValue.ToString

'Remove old Session
Session.RemoveAll()

'Define Report Session
Session("Year") = lstYear.SelectedItem.ToString
Session("Strategy") = lstStrategy.SelectedItem.ToString
Session("Objective") = lstObjective.SelectedItem.ToString
Session("Group") = lstRegional.SelectedItem.ToString
Session("StrategyID") = prmStratID
Session("GroupID") = prmRegID

Else
prmStratID = Request.QueryString("stratid")
prmObjID = Request.QueryString("objid")
prmRegID = Request.QueryString("value")

If prmStratID = String.Empty Then
'lstStrategy.SelectedIndex = -1
prmStratID = "02"
Else
lstStrategy.SelectedValue = prmStratID
End If
If prmObjID = String.Empty Then
'lstObjective.SelectedIndex = -1
prmObjID = "04"
Else
lstObjective.SelectedValue = prmObjID
End If
If prmRegID = String.Empty Then
'lstRegional.SelectedIndex = -1
prmRegID = "1"
Else
lstRegional.SelectedValue = prmRegID

End If

'Remove old Session
Session.RemoveAll()

'Define Report Session
Session("Year") = lstYear.SelectedItem.ToString
Session("Strategy") = lstStrategy.SelectedItem.ToString
Session("Objective") = lstObjective.SelectedItem.ToString
Session("Group") = stRegional.SelectedItem.ToString
Session("StrategyID") = prmStratID
Session("GroupID") = prmRegID
End If



BindData(prmStratID, prmObjID, prmRegID)
MapSwf = "mapSub" & prmRegID
MapValue = GetMapValue(prmStratID, prmObjID, prmRegID)
lnkBack.NavigateUrl = "./Page1.aspx?stratid" & prmStratID & "&objid=" & prmObjID
End Sub


Reply With Quote
  #2 (permalink)  
Old June 27th, 2007, 01:12 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 47
Thanks: 0
Thanked 2 Times in 2 Posts
Default

hi..
i don understand wat u want..as i understood it is like u want to change ur session variables that too wen the page.postback =true ....rite..?

or else don write the code just tell wat u want to do. like on click of wat u want wat...

Reply With Quote
  #3 (permalink)  
Old June 27th, 2007, 01:20 AM
Registered User
 
Join Date: Jun 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I want to get value of dropdownlist when the page is loaded first time

Reply With Quote
  #4 (permalink)  
Old June 27th, 2007, 06:31 AM
Authorized User
 
Join Date: Jun 2006
Location: , , .
Posts: 47
Thanks: 0
Thanked 2 Times in 2 Posts
Default

hi.
then just write.
//this even will occur only wen the page loads and not on any postback
if(!page.ispostback)
{
string val=urdropdownlist.val
}
else //wen ur get postback if u want then only include this.
{
ur other code.
}

Reply With Quote
  #5 (permalink)  
Old June 27th, 2007, 11:44 AM
Friend of Wrox
Points: 1,749, Level: 16
Points: 1,749, Level: 16 Points: 1,749, Level: 16 Points: 1,749, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

Quote:
quote:Originally posted by putputty
 I want to get value of dropdownlist when the page is loaded first time

The really for real first time? Like when someone types in www.yoursite.com and they show up at this page? In that case, you don't need to retrieve the value you need to SET the value.

You need to pick a default value (I use Visual Studio Express, it let's you choose which one easily, do you or are you hand coding?) The default value will be automatically populated in the dropdown. And if you're trying to style the highlight (red?) you can do that from your CSS file, just reset the background color. I admit CSS is not the easiest in .NET, but just add a CssClass property name and keep playing til you find what works. You just make do with the tools you've got and hope the next generation is more useful for professional grade, web standards based development.

-------------------------

Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe

When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper

Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get SelectedValue of Control obrienkev C# 2005 3 November 8th, 2007 12:17 PM
Unable to set SelectedValue on DropDownList jlrolin ASP.NET 2.0 Professional 0 April 13th, 2007 09:30 AM
DropDownList.SelectedValue weirdness Aaron Edwards ASP.NET 2.0 Basics 5 March 7th, 2007 12:39 AM
Assigning a SelectedValue in a DropDownList rit01 ASP.NET 2.0 Professional 3 March 25th, 2006 01:12 AM
comboBox.SelectedValue melvik C# 1 August 19th, 2003 09:21 AM



All times are GMT -4. The time now is 02:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.