NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Help with C# code

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search
5 members in live chat ~  


Reply
 
LinkBack Thread Tools
Old 05-11-2011, 09:48 AM THREAD STARTER               #1 (permalink)
Ik
Quality //
Join Date: Sep 2008
Posts: 911
Ik has much to be proud ofIk has much to be proud ofIk has much to be proud ofIk has much to be proud ofIk has much to be proud ofIk has much to be proud ofIk has much to be proud ofIk has much to be proud ofIk has much to be proud of
 


Breast Cancer Save a Life Alzheimer's Wildlife Wildlife

Help with C# code


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.
????: NamePros.com http://www.namepros.com/programming/714478-help-with-c-code.html

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:
????: NamePros.com http://www.namepros.com/showthread.php?t=714478

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
Ik is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Similar Threads
Thread Thread Starter Forum Replies Last Post
GoDaddy Discount Codes Iravan Domain Name Discussion 11510 Today 07:16 AM
Empire Technolgy 50% Off XEN or Virtuozzo Free cPanel or DirectAdmin Lowesthost Web Hosting Offers 0 05-07-2011 06:54 PM

 
All times are GMT -7. The time now is 02:47 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger