Hi,
I have an ASP.NET C# page that displays news.
I'm struggling giving a different class name for the current news item. I want to compare the query string with the current news public is. If it matches then I should give a specific class name for anchor tag.
Here is the repeater code:
and here is the code behind:
Please advise. Thanks
I have an ASP.NET C# page that displays news.
I'm struggling giving a different class name for the current news item. I want to compare the query string with the current news public is. If it matches then I should give a specific class name for anchor tag.
Here is the repeater code:
Code:
<asp:Repeater runat="server" ID="rpNews">
<ItemTemplate>
<a href='news.aspx?pid=<%#Eval("pubid") %>' class="news_header">
<%#Eval("title") %>
</a>
</ItemTemplate>
</asp:Repeater>
and here is the code behind:
Code:
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
public partial class news : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Get the MySQL connection string stored in the Web.config
string cnnString = ConfigurationManager.ConnectionStrings["SqlConnStr"].ConnectionString;
// Create a connection object and data adapter
SqlConnection conn = new SqlConnection(cnnString);
SqlConnection conn2 = new SqlConnection(cnnString);
// Create a SQL command object
string cmdText = "SELECT * FROM news ORDER BY dt DESC";
string cmdText2 = "";
if(Request.QueryString["pid"] == null)
cmdText2 = "SELECT TOP 1 * FROM news ORDER BY dt DESC";
else
cmdText2 = "SELECT * FROM news WHERE pubid = '" + Request.QueryString["pid"].ToString() + "'";
SqlCommand cmd = new SqlCommand(cmdText, conn);
SqlCommand cmd2 = new SqlCommand(cmdText2, conn2);
conn.Open();
SqlDataReader reader = cmd.ExecuteReader();
//SqlDataReader reader2 = cmd2.ExecuteReader();
rpNews.DataSource = reader;
rpNews.DataBind();
reader.Close();
conn.Close();
//rpLatest.DataSource = reader2;
//rpLatest.DataBind();
//reader2.Close();
SqlDataAdapter adapter = new SqlDataAdapter();
// Set the command type to StoredProcedure
cmd2.CommandType = CommandType.Text;
// Create and fill a DataSet
DataSet ds = new DataSet();
adapter.SelectCommand = cmd2;
adapter.Fill(ds);
string d = "";
string m = "";
string y = "";
foreach (DataRow dr in ds.Tables[0].Rows)
{
latestNewsTitle.Text = dr["title"].ToString();
y = dr["dt"].ToString().Substring(0,2);
m = dr["dt"].ToString().Substring(3,2);
d = dr["dt"].ToString().Substring(6,2);
latestNewsDate.Text = d + "/" + m + "/" + y;
latestNewsContent.Text = dr["content"].ToString().Replace("\r\n", "<br />");
latestNewsPic.Attributes.Add("src", "be/data/" + dr["pic"].ToString());
if (dr["pic"].ToString() == "")
latestNewsImageTr.Visible = false;
}
conn2.Close();
}
}
Please advise. Thanks





