为什么“链接按钮"控件变量没有任何值? [英] Why Link Button control variable dosen't get any value?

查看:52
本文介绍了为什么“链接按钮"控件变量没有任何值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,如果您能帮助我解决问题,我将不胜感激.

我创建了位于Repeater控件内部的LinkBut​​ton. CategoryID是LinkBut​​ton控件中的变量,在将Repeater控件绑定到数据后必须获取值.但是CategoryID总是为零.

我有以下ASP和C#代码:

Hello I would be grateful if you could help me to solve the problem.

I created LinkButton that located inside of Repeater Control. CategoryID is a variable in LinkButton Control that have to get value after Repeater Control was bound to data. But CategoryID always get zero.

I have the following ASP and C# code:

<asp:Repeater ID="rpt1" runat="server" 

    OnItemDataBound="rpt1_ItemDataBound" 

    OnItemCommand="rpt1_ItemCommand">    

 <div><%# Eval("Name") %>-<%# Eval("CollectionType")%>
 <asp:LinkButton ID="LinkButton1" runat="server" Text="[edit item]"  PostBackUrl='AddItem.aspx?CategoryID=<%# Eval("CollectionID")%>' /> 

  </div>     
  </ItemTemplate> 
 </asp:Repeater>



背后的代码:



Code behind:

public void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        List<GlassesCollection> gc = BL.GetDataBL.GetCollection();
        rpt1.DataSource = gc;
        rpt1.DataBind();
    }
}



知道为什么CategoryID变量没有任何值,如何解决该问题?



Any idea why CategoryID variable dosen''t get any value and how can i fix the problem?

Thank you in advance!

推荐答案

您要做什么,才能将状态从此页面持久化到另一个试图获取该值的页面?除非您发布到该页面,否则它不一定可以访问该页面上的变量,除非您正在做其他事情以在那里获取值.

我们可以看到您在转到另一页时正在做什么,以及另一页在读取值时正在做什么吗?
What are you doing to persist the state from this page to the other page where you are trying to get the value? Unless you POST to that page, it would not necessarily have access to variables on this page, unless you were doing something else to get the value there.

Can we see what you are doing to get to the other page, and what the other page is doing to read the value?


这篇关于为什么“链接按钮"控件变量没有任何值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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