Solved

.NET 2.0 dropdownlist objectdatasource selectedvalue

Posted on 2006-06-26
3
938 Views
Last Modified: 2008-02-01
Hi,

I have a dropdownlist which is filled by a objectdatasource (objectdatasourceid = "objectdatasourcedistrict"). This works, but I can't seem to get a selectedvalue until the dropdownlist is actually selected.

I think that the way it was done before, you could get a selectedvalue before the dropdownlist was actually selected. Can anyone tell me how I can get the first value that it is set to before the page postsback? I've tried .items.count, etc. and it all fails.

Thanks
0
Comment
Question by:Gezna
  • 2
3 Comments
 
LVL 2

Expert Comment

by:JocGaurav
ID: 16985472

source code plz
0
 

Author Comment

by:Gezna
ID: 16985882
Here you go. The below prints nothing until the page has posted back for the first time, but how do I get a hold of the value on the if not ispostback? The dropdownlist is full, but no value until postback...

Private Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
response.write(ddlDistrict.selectedvalue)
end sub

<asp:DropDownList ID="ddlDistrict"  DataSourceID="ObjectDataSourceDistrict" runat="server" DataValueField="intDistrictcd"  AutoPostBack="True" >

<asp:ObjectDataSource id="ObjectDataSourceDistrict" runat="server" SelectMethod="getUserDistricts" TypeName="BusinessLayer.UserRole" OldValuesParameterFormatString="original_{0}">
            <SelectParameters>
                <asp:Parameter Name="strAppName" Type="String" DefaultValue="INFRA" />
                <asp:SessionParameter Name="intObjectID" Type="Int32" SessionField="sesintObjectUserID"/>
               <asp:SessionParameter Name="intExecObjectID" Type="Int32" SessionField="sesintObjectUserID"/>
                <asp:Parameter Name="strSiteTypeCD" Type="String" DefaultValue="DO" />
            </SelectParameters>
        </asp:ObjectDataSource>
   
0
 
LVL 2

Accepted Solution

by:
JocGaurav earned 500 total points
ID: 16987232
just do  databind first time and it will work

sample code
------------------------------------------------------
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not (IsPostBack) Then
            DropDownList1.DataBind()
        End If
        Response.Write(DropDownList1.SelectedValue)
    End Sub
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now