带链接按钮的评估方法 [英] Eval Method with link button
问题描述
<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屋!