简体   繁体   中英

Asp.Net compiler error

Using Asp.NET 4 and c# and visual studio 2010. I have created a table that stores news in it and it's columns are news title , news text and news id which is the primary key.

I have a hyperlink in a grid view item template that gets it's text is from News Title in News table.

My grid view displays the information from News table(it displays News Title And News Text)

My hyperlink navigate url is to a page called news info. In the news info i have to labels so when you click on a news title that is a hyperlink in the gridview it will redirect you to News Info and in the news Info you will see news title and the news text in those two labels.

here's My hyperlink code in gridview :

 <asp:HyperLink ID="HyperLink112" runat="server" 
 NavigateUrl='~/Admin/NewsContentPage.aspx?NewsId=<%# Eval("NewsId") %>' Text='<%# Eval("NewsTitle") %>' />

And here's the code of the News info page Form_Load Event :

protected void Page_Load(object sender, EventArgs e)
{
    int newsid = Convert.ToInt32(Request.QueryString["NewsId"]);
    Label1.Text = newsid.ToString();
}

What when i click on a gridview title(I mean the hyperlink that shows News Title) I get this error:

Click here to see the Image

What Should i do?!

I think you've got problem with navigation url. Here is solution check some and select the best. Use construction like this:

NavigateUrl='<%# Eval("NewsId","~/Admin/NewsContentPage.aspx?NewsId={0}") %>'

As I said the problem is probablu with navigation url especially with string concatenation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM