Click here to Skip to main content
15,896,557 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
C#
<td align="center">
                               <asp:LinkButton ID="LinkButton4" PostBackUrl='<%# "~/ProductCatalog.aspx?ID="+Eval("ProductID") %>' runat="server"><5000</asp:LinkButton>
                           </td>


Eval method is not working with a link button.. what is the problem

on products catalog page
C#
string query = "Select * from Products where ProductID= '" + Request.QueryString["ID"].ToString() + "' AND UnitCost < 5000";
        //DataSet ds = new DataSet();
        DataSet ds=obj.fillgrid(query);
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind(); ;


i am getting error on that page that object referenc not set to instance of an object
Posted
Comments
Nigam Patel 26-Dec-11 22:40pm    
can you please past you code behind file code ? and if possible then also past you whole query so i have idea what is your problem?

 
Share this answer
 
Try following:
XML
<asp:LinkButton ID="LinkButton1" PostBackUrl='<%# String.Format("ProductCatalog.aspx?ID={0}",Eval("ProductID")) %>' runat="server"><5000</asp:LinkButton>


In addition if your ProductID data type is int then you need to use the following code:
C#
if(Request.QueryString["ID"]!="" && Request.QueryString["ID"]!=null){
string query = "Select * from Products where ProductID= " +Convert.ToInt32(Request.QueryString["ID"].ToString()) + " AND UnitCost < 5000";
}


UPDATED
*********************************

Assign this property at server side :
C#
LinkButton4.PostBackUrl = "ProductCatalog.aspx?ID=" + ProductID;


OR
Replace LinkButton by HyperLink as LinkButtons were originally designed to do a postback .
C#
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("ProductID", "ProductCatalog.aspx?ID={0}") %>'></asp:HyperLink>


Let me know your result.
 
Share this answer
 
v4
Comments
codegeekalpha 24-Dec-11 15:21pm    
nothing happenend.. page is even not redirected to product catalog.aspx
Monjurul Habib 24-Dec-11 15:35pm    
try my updated section and let me know
Monjurul Habib 24-Dec-11 15:36pm    
try: <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("ProductID", "ProductCatalog.aspx?ID={0}") %>'>
codegeekalpha 24-Dec-11 15:43pm    
hyperlink is not acting like a link.. its just a text i used this

<td align="center">
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("ProductID", "ProductCatalog.aspx?ID={0}") %>'>HyperLink
</td>
Monjurul Habib 24-Dec-11 15:56pm    
Try on code behind: HyperLink1.NavigateUrl="~/ProductCatalog.aspx?ID=" +ProductID+ "";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900