?
Solved

.NET 2.0 dropdownlist objectdatasource selectedvalue

Posted on 2006-06-26
3
Medium Priority
?
944 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

764 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