Solved

.NET 2.0 dropdownlist objectdatasource selectedvalue

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

705 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