Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 26th, 2004, 10:20 AM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with dropdown box

can anybody tell me i should make one dropdown field selected

protected DataTable GetFramleidandi()
    {
    Session["WebsiteID"] = 1;

    SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSe ttings.AppSettings["ConnectionString"].ToString ());
    SqlDataAdapter SqlDa = new SqlDataAdapter("SELECT id,Framleidandi FROM cars_Framleidandi ORDER BY Framleidandi", conn);
    DataSet ds = new DataSet();
    SqlDa.Fill(ds, "Framleidandi");
    return ds.Tables["Framleidandi"];
  }


<asp:DropDownList Runat="server"
                    Id="Framleidandi"
                    DataTextField="Framleidandi"
                    DataValueField="ID"
                    Datasource="<%# GetFramleidandi()%>"
                    />

Best regards Hlynur
 
Old August 26th, 2004, 11:11 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Put code in a page_unload event:

Framleidandi.SelectedValue = "<value>"

Brian
 
Old August 27th, 2004, 05:29 AM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

CS0246: The type or namespace name 'Framleidandi' could not be found (are you missing a using directive or an assembly reference?)


Line 139: SqlDa.Fill(ds, "Framleidandi");
Line 140: return ds.Tables["Framleidandi"];
Line 141: Framleidandi.SelectedValue = 28;
Line 142: }
Line 143:



Best regards Hlynur
 
Old August 27th, 2004, 05:34 AM
Registered User
 
Join Date: Aug 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am sorry posted wrong error code

Compiler Error Message: CS0246: The type or namespace name 'Framleidandi' could not be found (are you missing a using directive or an assembly reference?)

Line 119:void Page_Unload(object sender, EventArgs e)
Line 120:{
Line 121:Framleidandi.SelectedValue = 28;
Line 122:}
Line 123:

Best regards Hlynur
 
Old August 27th, 2004, 06:48 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

why in Page_Unload (your SelectedValue will not appear)
(you should change it somewhere like Page_Load or everywhere you need
except Page_Unload)
everything declared in Page_Unload will not appear in the page
the error tells you there is not a dropdown list
are you sure you have a line like below in your codebehind in your page class?
Code:
protected System.Web.UI.WebControls.DropDownList Framleidandi;

--------------------------------------------
Mehdi.:)
 
Old August 31st, 2004, 04:28 PM
Authorized User
 
Join Date: Jul 2004
Posts: 69
Thanks: 0
Thanked 1 Time in 1 Post
Default

Why not just set the SelectedValue property to the Value that you want it to be. If the value you set it to is not in the, the first value will be selected. You should do this in the Page_load, no Page_unload

www.CoderForRent.com
Get A Computer Job!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Property dropdown box in C# code-behind in VS jayaraj123 C# 2005 1 April 5th, 2007 12:54 AM
Standard Dropdown Combo box dartcoach VB How-To 8 November 8th, 2006 10:25 PM
How to integrate search function n a dropdown box jun9nah VB.NET 0 July 24th, 2006 10:12 PM
Changing font in dropdown box Bjoe HTML Code Clinic 4 April 24th, 2006 01:34 PM
Dropdown Box problem migarich ASP.NET 1.0 and 1.1 Basics 3 March 22nd, 2006 10:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.