add web.config value to gridview linkbutton or gridview inside <a> tag.. [Resolved]

Posted by Gopal_nivas under ASP.NET on 9/23/2010 | Points: 10 | Views : 2533 | Status : [Member] | Replies : 1

i have a gridview .. inside tat i was showing id and name values..
here i have linkbutton inside gridview..

<asp:LinkButton ID="lbtn_path" runat="server" Visible="true" PostBackUrl='<%# string.Format("System.Configuration.ConfigurationManager.AppSettings["path"].ToString()?ProductID={0}", Eval("ID")) %>'></asp:LinkButton> /

so here i want to add this web.config value inside my link button..
but it doesnt work..
how to add this in linkbutton..
and also is it possible to proceed the same login in <a> tag..


Posted by: SheoNarayan on: 9/23/2010 [Administrator] HonoraryPlatinum | Points: 50


In the above code snippet, you want to provide the path of a page from web.config appsetting that is not good. You should specify the path something like /yourfolder/yourpage.aspx?ProductID={0}.

In case you do not want to do this then you can declare a property (say Path) in the code behind and in Page_Load, assign that property to the AppSettings value and use that property.


Declare a protected method in the code behind something like

protected string WriteUrl(string productId)
return Path + "?ProductID="+ productId;

Now call the above method in the aspx page something like

<asp:LinkButton ID="lbtn_path" runat="server" Visible="true" PostBackUrl='<%# WriteUrl(Eval("ID").ToString())'></asp:LinkButton> 

Yes, you could have done this very well using anchor tag, its always best practice to use html control wherever possible to avoid unnecessary viewstate and processing time.

<a href="<%# WriteUrl(Eval("ID").ToString())">Click here</a> 

This should work for you.

Thanks for asking the question.

Sheo Narayan

Gopal_nivas, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response