Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 26th, 2007, 11:37 PM
Registered User
 
Join Date: Jun 2007
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


 
Old June 27th, 2007, 01:12 AM
Authorized User
 
Join Date: Jun 2006
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...

 
Old June 27th, 2007, 01:20 AM
Registered User
 
Join Date: Jun 2007
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

 
Old June 27th, 2007, 06:31 AM
Authorized User
 
Join Date: Jun 2006
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.
}

 
Old June 27th, 2007, 11:44 AM
Friend of Wrox
 
Join Date: Jun 2007
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.





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





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