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

  • Thread starter Thread starter to_rgoyal
  • Start date Start date
T

to_rgoyal

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.
 
rewrite the select query as,

SqlCommand getresult = new SqlCommand("select ' -None- ' Union select
distinct(owner) from
issue_log",con);
 
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.
 
Hi,
I got solution. Query should be "select '-None-' Owner union select
distinct(owner) Owner from issue_log".
 
Back
Top