hi all,

i had a problem with displaying the data in textbox.
My code is here

string note = "SELECT Notes,NDate FROM Ticket_Notes WHERE TicketNo ='" + tktno.Text + "' ";
        SqlCommand cmd3 = new SqlCommand(note, con);
        SqlDataReader id = cmd3.ExecuteReader();
        while (id.Read())
        {
              dnotes = id.GetValue(0).ToString();
              ndate = id.GetValue(1).ToString();
              description.Text = ndate + Environment.NewLine + dnotes ;
        }

If i have single row in database it works fine.But if i had multiple rows with same id then it should display one after another but it is over writing on it. How to display it one after the other..

Thank u.

to answer your question you have to concatenate the textbox like this

description.Text += ndate + Environment.NewLine + dnotes;

textBox is by default set to OneRow Text only. That means that the control does NOT have multiple rows.
If you want to show values in the textBox in rows, you hav to turn on "MultiLine" property (you have to set it to true), and its even good to define the scrollBars to Vertical:

textBox1.Multiline = true;
 textBox1.ScrollBars = ScrollBars.Vertical;

Now you can insert values inthe rows with using Environmetn.NewLine property.

Example:

string a = "a";
string b = "b";
textBox1.Text = a + Environment.NewLine + b;

i already enabled multiline to true.. let me explain u clearly..

dnotes = XXXX;
ndate = 1234;
now in description Textbox my value is
XXXX
1234

it is ok if i had only one value in dnotes and ndate if had another row like

dnotes = YYYY;
ndate = 9876;

Now my description textbox should look like this which i need
XXXX;
1234;

YYYY;
9876;

but the second row is over righting on the first one and displaying like
YYYY;
9876;

Sure. You use = mark. This will stsrt writing text from beginning.
Use += :

textBox1 += "Some vlaue" + Environment.NewLine + " Some other valaue";

In addition to the upper post you can use this in loop like if you have values in arrays then you can add like this.

for(int i=0;i<length;i++)
{
textBox1 += dnotes[i] +"\n" + ndate[i]+"\n"+"\n";
}

hey thanks.. this solved my problem

description.Text += ndate + Environment.NewLine + dnotes + Environment.NewLine + separator;

int[]a=new int[5]
1. for(int i=0;i<5;i++)
{
textbox1.text= textbox1.text + a
}

i already enabled multiline to true.. let me explain u clearly..

dnotes = XXXX;
ndate = 1234;
now in description Textbox my value is
XXXX
1234

it is ok if i had only one value in dnotes and ndate if had another row like

dnotes = YYYY;
ndate = 9876;

Now my description textbox should look like this which i need
XXXX;
1234;

YYYY;
9876;

but the second row is over righting on the first one and displaying like
YYYY;
9876;

jbisono gave you the perfect solution textbox1.text += dnotes + Environment.NewLine + ndate; or you can use textbox1.text += dnotes + "\r\n" + ndates;

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.