Problem with DropDownList: Each character gets a new line



i hope you can help me. I was looking for a solution in the internet but didn´t find a helpfull topic.

The problem relates on DropDownLists and DataGrids.

I´m requesting a dataset from an Access-Database and write the names of the colums to the console:

for (int i = 0 ; i <= myReaderCol.FieldCount -1; i++)





The problem appears when I´m filling a DDL or DG with these data:

for (int i = 0 ; i <= myReaderCol.FieldCount -1; i++)


DDL2.DataSource = myReaderCol.GetName(i);



The received strings are now splitted up and each character gets an own row like:






I want to see a full string in each row, where is the failure? 

Please help me.




12/14/2007 11:28:08 AM 93655 articles. 5 followers. Follow

9 Replies

Similar Articles

[PageSpeed] 54

You don't need to use for loop to assign values to DropDownList.

In this case you can assign the datareader to DataSource property of the drop down list. Also set the DataTextField and DataValueField properties to the column you want to display.

Please remember to Mark this post as Answered if it serves your purpose so that issue can be closed and others can refer.
12/14/2007 6:33:47 PM



thanks for your reply. Sure, it works without the loop, but the problem of the new lines remains. I´m sure it´s because of the .GetName-method. When I only use the records and not the .GetName-method it works fine without a loop an with every record :(



12/17/2007 7:06:44 AM

Try to remove the <br/> tag you have appended. I think thats the cause of your problem

So have it this way 



"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
12/17/2007 7:24:39 AM

Hello vinz,


the part with Response.Write is not the problem. This is just a controlling-function. It shows that the .GetName-method works and delivers the right columnames. The .DataBind on the webcontrol causes the problem with the new lines.




12/17/2007 7:31:59 AM

Can you post the GetName method? 


"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
12/17/2007 7:47:24 AM

sure, it´s from the objectbrowser in Visual Studio 2005:


Public Overrides Function GetName(ByVal index As Integer) As String

Member von System.Data.OleDb.OleDbDataReader


index The zero-based column ordinal.

Return Value

The name of the specified column.




12/17/2007 7:56:31 AM

It may be easier for you to see how it works in the browser

12/17/2007 8:27:59 AM


Instead of using Datasource and Datbind with DropDownList use DDL.Items.Add method like this,

for (int i = 0 ; i <= myReaderCol.FieldCount -1; i++)




Hope this helps you.


Mustakim Mansuri 


Mustakim Mansuri (MCTS, MCPD)
Cybage Software Pvt. Ltd.
12/17/2007 9:23:22 AM

Great, this works!

 Thanks a lot, Mustakim!



12/17/2007 9:32:04 AM

Similar Artilces:

Getting the Selected Item of dropdownlist inside Web User Control on a Web Form
Ive got a dropdownlist control inside a web user control called Entity.ascx. This web user control is on a webform.aspx. In Entity.ascx class I created a SelectedEntity property that returns the selected item in the dropdownlist. Inside webform.aspx when btnGo is pushed I set a string and pass it in the url. I am trying to get the entity they selected via the property (SelectedEntity) inside Entity.ascx. As the SelectedEntity property tries to return the selected item in the dropdownlist I get this error: System.NullReferenceException: Object reference not set to an instance...

How to get new web app to use .NET 2.0 on Win2K server using .NET 1.1 as default framework?
I have .net framework1.1 and 2.0 on our server running win2K. i have existing applications that uses 1.1, i also have a new app that use 2.0.  how can i set my new .NET 2.0 app to point to 2.0 without messing up my existing .NET 1.1 apps? To specify the ASP .Net version fro a web application, do the followingIn IIS Manager select the web application -> Properties -> ASP.Net TabSelect  ASP.Net version you want to use for the applicationRegards,PrashantDont forget to click "Mark as Answer" on the post that helped you. But I am running Win2K...

Implementing .Net Form into an web form, can this be done
I am new here, but have been searching for a while, and may not have the correct lingo to find what I am looking for.  I am tasked with implementing a .exe application that was writen vb6 then converted to .net into a new website my team is developing. The idea is to put each of the 3 different forms in this .exe application of 3 different .aspx pages. I have attempted multiple things to get this into the page and even started to just rewrite it as an web form, but even then I can't reuse any of the code since the System.Web.UI.Page doesn't inherit the sa...

Get message that mozilla has to close. Get booted out of web site. Get message from Mozilla to report problem. Problem reporting will not work. Eventually I delete the report message.
Name: Linnea Hagberg Email: lhagbergatsmithcovedotcom Product: Mozilla Suite Summary: Get message that mozilla has to close. Get booted out of web site. Get message from Mozilla to report problem. Problem reporting will not work. Eventually I delete the report message. Comments: See above. Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.12) Gecko/20050915 Firefox/1.0.7 ...

Problems with the .NET 2005 web form designer
In Visual Studio.NET 2003, building a web page was very similar to building a plain old form. In 2005, everything's changed. Every control gets shifted to the top left, I have to use panels and so on to separate things, and if I have to change something later it's an absolute nightmare. Am I really stuck with this, or is there some switch somewhere that will allow me to do things the way I'm used to?   Geoffrey Callaghan Try this.  Bring up an aspx page in design (not source) mode.  This will enable the Layout menu. Goto Layout->Position->Auto-Pos...

how can i get rid of these new line characters?
--0-1742231517-1033743619=:31985 Content-Type: text/plain; charset=us-ascii i have just started writing some scripts in PERL and i am trying to catch a deadline, i really wish i could get some help for this problem. any suggestion is greatly appreciated. i have a set of files with sequences aligned in the following format. i wonder how i can eliminate the new line characters within each sequence without touching those between sequences? ...... 2 chr1 10761 10775 chr19 46520370 46520384 + 941 acaGGAAAAGAACAA acaggaaaagaaggg 3 chr1 10776 11241 chrUn 45411478 45411944 - 12857...

character encoding problem with web service
Hi I am having a problem with a test VB.NET webservice communicating with a test TCP Listener. I can create a class that passes a string to the listener and accept a string based reply from the listener without any problems. However when I move the code into a webservice I get the following error message when I try to process the tcp listeners response: hexadecimal value 0x00, is an invalid character. Line 1, position 346 I am guessing that it is some sort of encoding problem??? Here is the web service code that calls the tcp listener ************************************...

Problem getting DTS object to work on a Web form
Hi;  I would like to run a DTS package from the On click button event on a web form. I tried using code that works in a windows form. But, VS 2005 doesn't like the code. Here are the libraries that I used with the windows form.  Imports System, Imports System.Data. Imports System.Data.SqlClient. Is there a library that I am missing ? And here are the lines of code that won't compile:  Dim oPackage As New DTS.Package2Class Dim oStep As DTS.Step Package.LoadFromSQLServer("123WXYZ\TRSQL", , , DTS.DTSSQLServerStorageFlags.DTSSQLStgFlag_UseTrustedConnection, , , ,...

Problem creating new web forms and user controls
I have been coding .net for almost a year. Three days ago I created a new project and then some new web forms. Compiled, then viewed the site. I get an error saying it cannot load type - then shows the inherited class for the code behind of the page. This is only happening in certain sites, and we have strict procedures when creating them. They are all the same. Any help would be great Check if you are creating the name spaces properly...(if you have any) rebuild the whole project and then try it out...Hey! It compiles! Ship it! Cheers, Venugopal Mallarapu. Visit : My Blog...

Problem with ~n (new line escape characters ) in w_message
Hello, We were using MessageBox to display all our messages. but due to localization we have decided to use Of_message() of error service... the problem we are now facing is with escape characters ( ~r ~n) not working with mle. e.g. error.gif any idea how to solve this issue... PB 9.0.1 -Charles begin 666 error.GIF M1TE&.#EA( )^`/<``````( ```" `(" ````@( `@ " @(" @,# P/\```#_ M`/__````__\`_P#______P`````````````````````````````````````` M```````````````````````````````````````````````````````````` M````,P``9@``F0``S ``_P`S```S,P`S9@`SF0`...

Entering data in old aspx form only after saving data in new web form opened in new window
Dear all, i am facing a problem. please solve it. i have created two .aspx pages, say, page1.aspx and page2.aspx. with the help of client-side javascript i am opening page2.aspx from page1.aspx in a new window. So, page1.aspx and page2.aspx remains open at the same time. what i want is, i don't want the user to able to activate or enter data in page1.aspx without saving data in page2.aspx. regards subhajit use window.showModalDialog() instead of when the child window is closed, in this case, program execution continues on the next line after the showModalDialog...

New Form
I need to create a form that will post to a different page outside of the portal Virtual directory, when I do this the form either postsback to itself or does nothing. how do I get this resolved? I need it to be a form because I don't want the address to display the info.. Example Don't want Please helpKeith K. Kowalski There are a couple of problems when trying to add forms to your aspx pages. First of all, the reason .NET is able to do all of it's fancy-schmancy event handling is through the use of a big fat form. ...

getting start with and crystal repots(web form)
I use Crystal Report9 in Visual Studio.NET 2003..... Example at Northwind database I want a application that.....a form include a combobox that contain CustomerID.....If I choose one CustomerID and click OK button....a Report will display information about this Customer......I think that must use to do that ???? (How do I start to coding --please step by step or sample) please help me !!! Thank you so much!!! very good I have Dropdownlist when I choose the 'month'--> the all data of this field will show I use this Private Sub ddlMonth_Sel... web forms wysiwyg resize row problem
I don't know if someone ever when throw this problem, but something weird is happening with the wysiwyg from web forms of .net, the problem is the following: sometimes when i'm selecting a control in the HTML mode it selects to resize the row by mistake, the resize mouse pointer appears and i click to drop the resize mode, but then i'm not allowed to go outside of the table that i resized the row even dropping the resize mode, i try to change to code mode, and it allows to go beond the table but when i get cack to HTML mode it doesm't i'm forced to restart the, this is quite anoyng...

Web resources about - Problem with DropDownList: Each character gets a new line -

Resources last updated: 12/24/2015 7:58:37 PM