497988 Simple ASP.NET C# Code Fix

Completed Posted May 12, 2011 Paid on delivery
Completed Paid on delivery

Hi,

I'm using a repeater to list news article titles on a page. Once a title is clicked, the page reloads with the news details.

What I want to achieve is to compare the query string with the current news ID. If they are equal, then I want to give a different class name for the anchor tag to make the link highlighted with a different color.

It seems the repeater has some limitations. I want a fix for this, or an alternative for the repeater.

I need C# code sample please.

Here is my code:

----------------------------------------

ASPX Page:

----------------------------------------

<asp:Repeater runat="server" ID="rpNews">

<ItemTemplate>

<a href='[url removed, login to view];%#Eval("pubid") %>' class="news_header">

<%#Eval("title") %>

</a>

</ItemTemplate>

</asp:Repeater>

----------------------------------------

Code Behind:

----------------------------------------

using System;

using [url removed, login to view];

using [url removed, login to view];

using [url removed, login to view];

using [url removed, login to view];

using [url removed, login to view];

using [url removed, login to view];

using [url removed, login to view];

public partial class news : [url removed, login to view]

{

protected void Page_Load(object sender, EventArgs e)

{

// Get the MySQL connection string stored in the [url removed, login to view]

string cnnString = [url removed, login to view]["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([url removed, login to view]["pid"] == null)

cmdText2 = "SELECT TOP 1 * FROM news ORDER BY dt DESC";

else

cmdText2 = "SELECT * FROM news WHERE pubid = '" + [url removed, login to view]["pid"].ToString() + "'";

SqlCommand cmd = new SqlCommand(cmdText, conn);

SqlCommand cmd2 = new SqlCommand(cmdText2, conn2);

[url removed, login to view]();

SqlDataReader reader = [url removed, login to view]();

[url removed, login to view] = reader;

[url removed, login to view]();

[url removed, login to view]();

[url removed, login to view]();

SqlDataAdapter adapter = new SqlDataAdapter();

[url removed, login to view] = [url removed, login to view];

DataSet ds = new DataSet();

[url removed, login to view] = cmd2;

[url removed, login to view](ds);

string d = "";

string m = "";

string y = "";

foreach (DataRow dr in [url removed, login to view][0].Rows)

{

[url removed, login to view] = dr["title"].ToString();

y = dr["dt"].ToString().Substring(0,2);

m = dr["dt"].ToString().Substring(3,2);

d = dr["dt"].ToString().Substring(6,2);

[url removed, login to view] = d + "/" + m + "/" + y;

[url removed, login to view] = dr["content"].ToString().Replace("\r\n", "<br />");

[url removed, login to view]("src", "be/data/" + dr["pic"].ToString());

if (dr["pic"].ToString() == "")

[url removed, login to view] = false;

}

[url removed, login to view]();

}

}

.NET ASP C# Programming MySQL Odd Jobs SQL

Project ID: #2243905

About the project

1 proposal Remote project Active Jul 11, 2012

Awarded to:

annsys

Hi choose me...

$25 USD in 0 days
(135 Reviews)
5.9