473,411 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

How can I append one more record while populating DropDownList using Database.

Hi All,
I am creating one web base application using ASP.net and C#. I am
populating dropdown lists of my web

pages using database. I am using this code:

con = new SqlConnection(connectionString);
SqlCommand getresult = new SqlCommand("select distinct(owner) from
issue_log",con);
con.Open();

sqlReader = getresult.ExecuteReader();

OwnerDropDownList.DataSource=sqlReader;
OwnerDropDownList.DataTextField="Owner";
OwnerDropDownList.SelectedIndex=0;

OwnerDropDownList.DataBind();

sqlReader.Close();

con.Close();

After using this, my dropdown list is successfully populated with table
values.
But I also want to add one more value with text 'None' and value ''
to my dropdown list with selected= truth.

That is it should be default value of my dropdownlist.How can I do
this?
I tried to add this value using visual studio development
environment. But, it is not being appended with

table values.

Please help me. Thanks in advance.

Nov 17 '05 #1
3 4049
rewrite the select query as,

SqlCommand getresult = new SqlCommand("select ' -None- ' Union select
distinct(owner) from
issue_log",con);

--
Regards,
Amal
http://geocities.com/techsharing
"to*******@yahoo.com" wrote:
Hi All,
I am creating one web base application using ASP.net and C#. I am
populating dropdown lists of my web

pages using database. I am using this code:

con = new SqlConnection(connectionString);
SqlCommand getresult = new SqlCommand("select distinct(owner) from
issue_log",con);
con.Open();

sqlReader = getresult.ExecuteReader();

OwnerDropDownList.DataSource=sqlReader;
OwnerDropDownList.DataTextField="Owner";
OwnerDropDownList.SelectedIndex=0;

OwnerDropDownList.DataBind();

sqlReader.Close();

con.Close();

After using this, my dropdown list is successfully populated with table
values.
But I also want to add one more value with text 'None' and value ''
to my dropdown list with selected= truth.

That is it should be default value of my dropdownlist.How can I do
this?
I tried to add this value using visual studio development
environment. But, it is not being appended with

table values.

Please help me. Thanks in advance.

Nov 17 '05 #2
Hi ,
I changed the select query. But, now application is giving run time
error :

Server Error in '/viewissue' Application.
--------------------------------------------------------------------------------

DataBinder.Eval: 'System.Data.Common.DbDataRecord' does not contain a
property with the name Owner.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.Web.HttpException: DataBinder.Eval:
'System.Data.Common.DbDataRecord' does not contain a property with the
name Owner.

Source Error:
Line 103: //OwnerDropDownList.SelectedIndex=0;
Line 104:
Line 105: OwnerDropDownList.DataBind();
Line 106: sqlReader.Close();
Line 107:
What should I do, to get rid of this error.

Nov 17 '05 #3
Hi,
I got solution. Query should be "select '-None-' Owner union select
distinct(owner) Owner from issue_log".

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: cloverme | last post by:
Hi, I need help populating a listbox from a database on a webform. I created a an access database with a table, fields and data. Then I created a WebForm in vb.net and added a DropDownList...
2
by: Paul Wagstaff | last post by:
Hi there I have 2 tables: tblAccuracy & tblClearance Users add new records to tblAccuracy using frmRegister. Under specific conditions I need to append the current record from frmRegister into...
2
by: Mark | last post by:
I have a FE/BD 2002 DB on a XP pro platform. I know this is ugly but it works for me...... A text file is produced from our Oracle WMS. (Average 20k records) A command button deletes all records...
3
by: RFS666 | last post by:
Hello together, I tried to find out about populating an asp.net server control (a dropdownlist) from the clientside jscript, but I didn't find a solution up to now. I cannot use a html...
6
by: p.mc | last post by:
Hi all, I have a MS SQLServer database which has two tables, 'images' and 'photographers'. The photographer table contains a field for PhotographerID and a one for PhotographerName. The image...
6
by: needin4mation | last post by:
I have a gridview and a dropdownlist. If I change the ddl, the gridview populates. That is what I want. But what I don't want is for it to happen the first time they get to the page. I know I...
0
by: koonda | last post by:
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my...
10
by: pythonnoob | last post by:
Hello everyone. New to python as well as this forum, but i must say ive learned a but already reading through some posts. Seems to be a pretty helpful community here. Before i post a question...
2
by: RobertTheProgrammer | last post by:
Hi again, Okay, I decided the GridView is the way to go to solve my problem. But now I've got another problem. I've found plenty of examples about how to add a DropDownList item to the grid...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.