Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics 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 December 22nd, 2006, 10:18 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with dropdownbox

hello,
I have two problem with drop down box. These are...

1. I have two tables. One is country_master and other is user_master. In the user registration form, there is a drop down box for countries which I'm filling from the country_master table and it is running well. Now I want a "---Select---" entry at the beginning of drop down box. How I can do this?

2. I am storing the country_id in the user_master table. User can edit there profile. Now when user open the profile for editing the entire form is filled with old values. Now the problem is that how I can show the last selected country name in the drop down box?
By the way I am new in .net. Please help me.
regards,
__________________
Angshujit
 
Old December 23rd, 2006, 04:37 AM
Authorized User
 
Join Date: Aug 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to amit_mande@yahoo.com Send a message via AIM to amit_mande@yahoo.com Send a message via MSN to amit_mande@yahoo.com Send a message via Yahoo to amit_mande@yahoo.com
Default

soln:
1)You have to set "selected" property for "---Select---" as true in <asp:Dropdownlist> tag.
2)select country_id and accordingly depending on this id set "selected" property true for that country_id

I think this is right

 
Old December 26th, 2006, 07:59 AM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deb1980
Default


Hi Amit,

Could you please check this, as I think this way its not possible if you are using a ASP.net component combo box?


Cheers!

Debashis



 
Old December 27th, 2006, 03:21 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi amit

thanks for reply. But I think I cannot make you understand my problem. So I am sending you my code :

Here is the code for .aspx file (only drop down box) -
<asp:dropdownlist id="lstCountry" DataValueField="country_id" DataTextField="country_name" Runat="server"></asp:dropdownlist>

And here is the code for C# file ('con' is the connection object)-
SqlDataAdapter da = new SqlDataAdapter("Select * from country_master", con);
DataSet ds = new DataSet();
da.Fill(ds, "country");
lstCountry.DataSource = ds.Tables["country"];
lstCountry.DataBind();

Now how and where i should use 'selected' option ?
Angshujit
 
Old December 27th, 2006, 06:04 AM
Authorized User
 
Join Date: May 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

use this to insert ---Select--- at start of list

lstCountry.DataSource = dsProducts;
lstCountry.DataBind();
lstCountry.Items.Insert(0, new ListItem("---Select---"));

Regards,
Rashida Jabeen
http://www.akaas.net
 
Old December 28th, 2006, 03:03 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello, iamrashida83

Thank you for your help. It is working fine. Please help me to solve my second problem. That is in the time of editing, I want to display the previously selected country in the drop down box. How I can select that ? I am storing the country_id in the user_master table.

Please help me.
Angshujit
 
Old December 28th, 2006, 03:48 AM
Authorized User
 
Join Date: May 2006
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

@angshujit:

it depends on ur DB design
are u storing countryid or country name in user_master table?

better way is to store countryid of selected country in the matser table. To load previous values select all values from table and get it in a datatable suppose dtMember

u have to bind countries in dropdownlist like:
lstCountry.DataSource = dtCountries;
lstCountry.DataTextField = "CountryName"; //name of column of data table
lstCountry.DataValueField = "CountryID" //name of column of data table
lstCountry.DataBind();
lstCountry.Items.Insert(0, new ListItem("---Select---"));

now while loading the users u can sleect the country from dropdownlist using the id of country stored in user_master table

so try this

lstCountry.SelectedValue = ---- // country id u fetched from member's table

Regards,
Rashida Jabeen
http://www.akaas.net
 
Old December 28th, 2006, 09:39 AM
Authorized User
 
Join Date: Dec 2006
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hello Rashida Jabeen,

Thanks for your help. It is working fine.

Angshujit






Similar Threads
Thread Thread Starter Forum Replies Last Post
Iterating through DropDownBox rsearing ASP.NET 2.0 Basics 8 January 3rd, 2007 04:35 PM
DropDownBox inside FormsView - Urgent shaly ASP.NET 2.0 Basics 1 December 6th, 2006 05:52 PM
Combining Two DataTextField's for a DropDownBox testsubject ADO.NET 1 January 3rd, 2006 12:34 PM
Combining Two DataTextField's for a DropDownBox testsubject VB.NET 1 January 3rd, 2006 12:32 PM





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