I am having problems in setting a up a latest news panel on my website.
Currently
public System.Data.SqlClient.SqlConnection Admin_conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectString"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = News();
if (dt.Rows.Count > 0) // Check if the DataTable returns any data from database
{
lbltest.Text = dt.Rows[0]["NewsTitle"].ToString();
lblDate.Text = dt.Rows[0]["NewsDate"].ToString();
lbldescription.Text = dt.Rows[0]["NewsDescription"].ToString();
}
}
protected DataTable News()
{
DataTable dt = new DataTable();
SqlDataAdapter data = new SqlDataAdapter("SELECT NewsTitle, NewsDescription, NewsDate FROM News WHERE [NewsDate] < getdate()", Admin_conn);
data.Fill(dt);
return dt;
}
But the above code just display news of single row.. I want to display all the news on my website. Which control should I use to display all the records from the database in a proper order like news title, news description then the next news title and description…..
Is there any way to use ajax accordion so that all the news title will be displayed and when I click on the specific news title, the description of that news will be displayed.
Any suggestions or tutorial will be highly appreciated..
I believe you are looking for the ListView Control.
It will allow you to bind to the entire set of rows being returned from the database and provide a template for each item.
You can also take a few minutes to watch this video tutorial from Microsoft:
The ListView Control: The Official Microsoft ASP.NET Site