Change font family and size of paragraph using CSS in ASP.Net

Last Reply 6 months ago By pandeyism

Posted 6 months ago

i am working on bootstrap.i have used Paragraph tag whose id=newscontent and newscontent is coming from database.

i wanted to change the font-size and font-family of newscontent but its not getting changed.Any help will be highly appreciated.

i have the follow code:

 <div class="container">
        <div class="newscon">
            <h2 ><b style="font-family:Arial, Helvetica, sans-serif; color:#1ea421">
		  <asp:Label ID="newsheader" runat="server" Text=""></asp:Label></b></h2>               
            <br />    
              <asp:Image runat="server" ID="ImgNews" ImageAlign="Left" Height="200px" Width="300px" style="float:left; margin:5px 10px 10px 0;       
	           padding: 5px;"/> 
             <p runat="server" style="text-align:justify;font-family:poppins;font-size:26px;" id="newscontent"></p>
	    </div>
</div>

code behind:

 

                    if (r.Read())
                    {
                        newsheader.Text = HttpUtility.HtmlDecode(r["newstitle"].ToString().Trim()).ToString();
                       newscontent.InnerHtml = HttpUtility.HtmlDecode(r["newsBody"].ToString().Trim()).ToString();                                         
                        ImgNews.ImageUrl = "~/images/newspictures/" + r["image"].ToString();//added by chetan for localhost               
                       ImgNews.Height = 200;
                        ImgNews.Width = 300;                                          
                    }

 

You are viewing reply posted by: pandeyism 6 months ago.
Posted 6 months ago Modified on 6 months ago

Hi chetan,

Please take reference the below code and correct your code.

HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
    <script type="text/javascript" src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css" />
    <link href='https://fonts.googleapis.com/css?family=Poppins' rel='stylesheet'>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div class="container">
            <div class="newscon">
                <h2>
                    <b style="font-family: Arial, Helvetica, sans-serif; color: #1ea421">
                        <asp:Label ID="newsheader" runat="server" Text=""></asp:Label></b></h2>
                <br />
                <asp:Image runat="server" ID="ImgNews" />
                <p runat="server" style="text-align: justify; font-family: 'Poppins'; font-size: 30px;"
                    id="newscontent">
                </p>
            </div>
        </div>
    </div>
    </form>
</body>
</html>

Namespaces

C#

using System.Data.SqlClient;
using System.Configuration;

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!this.IsPostBack)
    {
        string str = ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
        using (SqlConnection con = new SqlConnection(str))
        {
            using (SqlCommand cmd = new SqlCommand("SELECT Name, Country FROM Customers", con))
            {
                con.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    newsheader.Text = HttpUtility.HtmlDecode(dr["Name"].ToString());
                    newscontent.InnerText = HttpUtility.HtmlDecode(dr["Country"].ToString());
                    con.Close();
                }
            }
        }
    }
}

Screenshot