user2154272
user2154272

Reputation: 17

asp.net c# marquee with sql ,innertext not use new line

I'm new in programming field ......so please give proper answer for that que.

I'm using dynamic marquee with sql database for "company news", there code run properly but marquee not create new line for new point.

html code:

<asp:Panel ID="Panel1" runat="server" CssClass="style42" Width="762px" 
    BorderStyle="Solid" Font-Bold="True" Font-Size="Medium" BackColor="#78BBE6" 
    Height="267px">
    <div style="width: 762px; " class="style41">
       <marquee id="mar1" runat="server" direction="up" onmouseover="this.stop()" 
                onmouseout="this.start()" scrollamount="2" scrolldelay="1" 
                class="style43" >
            <strong>
            </strong>
       </marquee>   
    </div>
</asp:Panel>

c# code:-

protected void Page_Load(object sender, EventArgs e)
{
    SqlConnection obj = new SqlConnection("data source=DHAVAL-PC;"+
                       "initial catalog=user_master;"+
                       "integrated security=true;user id=sa;password=1234");
    string login1 = "select * from admin_data";
    SqlCommand cmd1 = new SqlCommand(login1,obj);
    obj.Open();
    SqlDataReader user = cmd1.ExecuteReader();
    if (user.HasRows)
    {
        user.Read();
        SqlDataReader t1;
        user.Close();
        t1 = cmd1.ExecuteReader();
        t1.Read();               
        this.mar1.InnerHtml= t1[6].ToString();  
           //what to do for newpoint in newline                             
        obj.Close();
     }
 }

there in my database only one field for entering news containts... when use textbox for display news it work good..it show new point in new line..but marquee not display like textbox.

please give me proper suggestion .....

Upvotes: 1

Views: 2570

Answers (2)

Markus Palme
Markus Palme

Reputation: 689

Entering a newline in a textbox produces a newline character (\n) in C#. HTML ignores newline characters, to force a newline in HTML you have to use the <br />tag:

this.mar1.InnerHtml= t1[6].ToString().Replace("\n", "<br />");

Upvotes: 2

शेखर
शेखर

Reputation: 17614

You need to change this line

 this.mar1.InnerHtml= t1[6].ToString();  
       //what to do for newpoint in newline     

to

 this.mar1.InnerHtml+= t1[6].ToString()+"<br/>";  
       //what to do for newpoint in newline     

or you have new line character in your single record then you should do like this

this.mar1.InnerHtml+= t1[6].ToString().Replace("\n", "<br />");

Upvotes: 0

Related Questions