NameSilo

Help with C# code

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch

Ik

Quality //VIP Member
Impact
8
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:

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
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back