Solved

.NET 2.0 dropdownlist objectdatasource selectedvalue

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

16 Experts available now in Live!

Get 1:1 Help Now