Friday, November 26, 2010

displaynews

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Displaynews : System.Web.UI.Page
{
    SqlDataAdapter da;
    SqlDataReader dr;
    DataSet ds = new DataSet();
   

  SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings.Get("connString"));
    DBUpdate dispNews = new DBUpdate();
    SqlCommand cmd = new SqlCommand();
   
   

    protected void Page_Load(object sender, EventArgs e)
    {
        
       
        string  date = DateTime.Now.ToString();
        if (!IsPostBack)
        {

            Repeater1.DataSource = GetData();
            Repeater1.DataBind();
            da = new SqlDataAdapter("SELECT top 5 * ,'~/Reporter/images/'+image as im  FROM tblNews order by postedDate desc", con);

            da.Fill(ds, "newscontents");
            DataList1.DataSource = ds.Tables["newscontents"];
            DataBind();
           
        }}

         public DataSet GetData()
    {

        dispNews .getcon();
        DataSet ds = new DataSet();
        DataTable dt = new DataTable("News");
        DataRow dr;
        string strSql = "SELECT top 5 * FROM tblNews order by postedDate desc";
        SqlDataAdapter da = new SqlDataAdapter(strSql,dispNews .con);
        da.Fill(dt);
        //dt.Columns.Add(new DataColumn("Id", typeof(Int32)));
        //dt.Columns.Add(new DataColumn("Url", typeof(string)));

        //dt.Columns.Add(new DataColumn("Desc", typeof(string)));
        for (int i = 1; i <= 4; i++)
        {
            dr = dt.NewRow();
            //dr[1] = i;
            //dr[2] = "link" + i.ToString();

            //dr[2] = "Title " + i.ToString();
            dt.Rows.Add(dr);
        }
        ds.Tables.Add(dt);
        Session["dt"] = dt;
        return ds;
        dispNews.con.Close();
    }
    
 }

No comments:

Post a Comment