2

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?!

Mohammadali Talaie
  • 118
  • 1
  • 1
  • 10
  • Could you please post the url that is rendered? This is can be done by simply hovering over the link. If you hover over the link then at the left bottom of your browser the link would appear. Thanks – Christos Oct 31 '15 at 11:04
  • i guess the newsId which is passed in the query string is not a valid int, hence the format exception...Did you check what is the value of Request.QueryString["NewsId"] by debugging? – Dalton Oct 31 '15 at 11:13
  • @Christos Here's the URL **localhost:1322/WebSite1/Admin/NewsContentPage.aspx?newsId= <%# Eval("NewsId") %>** – Mohammadali Talaie Oct 31 '15 at 11:26
  • As you can see that's the problem...The url you build is not correct. I mean the binding doesn't work correctly. If it was correct, you have seen something like this localhost:1322/WebSite1/Admin/NewsContentPage.aspx?newsId=1 . – Christos Oct 31 '15 at 11:28
  • @Dalton What do you mean by that how can i find out what is the value of the Request.QueryString["NewsId"] by debugging? – Mohammadali Talaie Oct 31 '15 at 11:28
  • @Christos Now what should i do? – Mohammadali Talaie Oct 31 '15 at 11:29
  • Please try this NavigateUrl="~/Admin/NewsContentPage.aspx?NewsId="+'<%# Eval("NewsId") %>' – Christos Oct 31 '15 at 11:30
  • I have changed the navigate url to this : `'~/Admin/NewsContentPage.aspx?NewsId= + <%# Eval("NewsId") %>'` – Mohammadali Talaie Oct 31 '15 at 11:34
  • but i still get that problem – Mohammadali Talaie Oct 31 '15 at 11:34

1 Answers1

0

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.

Community
  • 1
  • 1
ElConrado
  • 1,477
  • 4
  • 20
  • 46