Solved

.NET 2.0 dropdownlist objectdatasource selectedvalue

Posted on 2006-06-26
3
941 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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

809 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