【发布时间】:2011-04-05 10:28:48
【问题描述】:
public partial class newsarticle : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int article_id = Convert.ToInt32(Request.QueryString["id"]);
string select = "SELECT [ID],[NEWS],[CONTENTS] FROM [NEWS]";
string strCon = System.Web
.Configuration
.WebConfigurationManager
.ConnectionStrings["ConnectionString"]
.ConnectionString;
SqlConnection conn = new SqlConnection(strCon);
conn.ConnectionString = strCon;
conn.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand(select, conn);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
news_title.Text = myReader["NEWS"].ToString();
news_content.Text = myReader["CONTENTS"].ToString();
}
conn.Close();
}
}
你好,我对这种方法有疑问。我将 DB 中的这些“新闻”和“内容”与 news_title 和 news_content 连接起来,在 newsarticle.aspx 站点中,我有两个用于编写新闻和内容的文字控件。我有
<a href="/newsarticle.aspx?id=<%#Eval("ID") %>">
<asp:Label ID="lblTitle" runat="server" Text='<%#Eval("News") %>'>
</asp:Label>
</a>
, 有了这个,我得到了新闻名称的链接,当我点击一个链接时,它总是返回我的姓氏和来自表的内容。例如。如果我有 4 个赞,当我点击 2 时,我会从 4 个链接获得结果。 有人知道有什么办法吗?
【问题讨论】: