带链接按钮的评估方法 [英] Eval Method with link button

查看:66
本文介绍了带链接按钮的评估方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<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

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

推荐答案

检查此博客
http://stackoverflow.com/questions/2637330/databinder-eval-in-c-sharp [ ^ ]
--NDK
check this blog
http://stackoverflow.com/questions/2637330/databinder-eval-in-c-sharp[^]
--NDK


请尝试以下操作:
Try following:
<asp:LinkButton ID="LinkButton1" PostBackUrl='<%# String.Format("ProductCatalog.aspx?ID={0}",Eval("ProductID")) %>' runat="server"><5000</asp:LinkButton>



另外,如果ProductID 数据类型为int,则需要使用以下代码:



In addition if your ProductID data type is int then you need to use the following code:

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 :

LinkButton4.PostBackUrl = "ProductCatalog.aspx?ID=" + ProductID;




LinkButton 替换为HyperLink ,因为LinkButtons最初是用于回发的.



OR
Replace LinkButton by HyperLink as LinkButtons were originally designed to do a postback .

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("ProductID", "ProductCatalog.aspx?ID={0}") %>'></asp:HyperLink>



让我知道你的结果.



Let me know your result.


这篇关于带链接按钮的评估方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆