Home > ASP.Net > Display data from Database in Marquee

Display data from Database in Marquee


try this example:

Step1 :- Open SQL Server 2005 and create Database has Table News has the following fields:
-Id int , PK
-Title nvarchar(50)
-Description nvarchar(max)
-PostDate datetime
-Show bit
Step2:- Open VS2005 and create new Website and add new web page called  ShowNews.aspx

<asp:Literal ID="Literal1" runat="server"></asp:Literal>
<script language="javascript" type="text/javascript">
function Openpopup(Id)
winpops = window.open("News_Detail.aspx?News_Id="+Id,"","width=440, height=250, left=45, top=15, scrollbars=yes, menubar=no,resizable=no,directories=no,location=no")

and in code behind :

protected void Page_Load(object sender, EventArgs e)

        SqlConnection myCon = new SqlConnection(ConfigurationManager.ConnectionStrings["Bag_ConnStr"].ConnectionString);

        string strSql = "SELECT Top(5)* FROM News where(Show='true') order by PostDate desc";
        SqlCommand myComd = new SqlCommand(strSql, myCon);
        SqlDataReader sqlRdr;
        string x="";
            sqlRdr = myComd.ExecuteReader();
            x = "<Marquee OnMouseOver='this.stop();' OnMouseOut='this.start();' scrollamount='2'  width='40%'>";
            while (sqlRdr.Read())
                x += "&nbsp;||&nbsp;";
                x += "<a href='#' OnClick=Openpopup(" + sqlRdr["Id"].ToString() + ")>";
                x += "</a> &nbsp;||&nbsp; ";
            x += "</Marquee>";
            Literal1.Text = x;
        catch (Exception msg)

Good Luck

Categories: ASP.Net
  1. Ali
    April 20, 2009 at 4:59 pm

    Thanx so much

  2. yasserzaid
    April 20, 2009 at 9:36 pm

    You are welcome Ali

    Good Luck

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: