如何访问数据列表标题中的页脚标签 [英] how to access footer label in header in datalist

查看:85
本文介绍了如何访问数据列表标题中的页脚标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在使用嵌套数据列表.在嵌套数据列表中,我正在使用页眉模板和页脚模板.我在页脚模板中绑定了2个标签.
现在如何访问标头模板中的这2个标签值.

因为当我单击标题模板linkbutton时,我需要这个2个标签值.

我将尝试此代码(如下所示)
Int16 post_id = Convert.ToInt16(((Label)e.Item.FindControl("Label3")).Text);

它给出如下错误:对象引用未设置为对象的实例.



谢谢.
Shailesh prajapati.

Hello,

I am using nested datalist. in nested datalist i am using header template and footer template. i am binding 2 labels in footer templates.
now how to access this 2 labels value in header templates.

because when i click on header templates linkbutton that time i need this 2 labels value.

i will try this code (given below)
Int16 post_id = Convert.ToInt16(((Label)e.Item.FindControl("Label3")).Text);

It gives error like : Object reference not set to an instance of an object.



Thanks.
Shailesh prajapati.

推荐答案

在页脚中找到控件时,需要添加其他条件.

As you are finding the control in your Footer, you need to add additional condition.

if (e.ItemType == ListItemType.Footer)
{
   int post_id = Convert.ToInt16(((Label)e.Item.FindControl("Label3")).Text); 
}





如果确实有帮助,则将其标记为答案.





Mark it as answer if it is really helpful.


当然,在使用FindControl获取Label3时,您可能会得到Brij建议的NULL.

如果您很确定在那里有标签,请检查 Label3 中的某些字符是大写还是小写.
Off course You might getting NULL as Brij suggested while getting Label3 using FindControl.

If you''re very sure on lable there, Then check proper spelling whether some character in upper or lower case in Label3.


Label id= (Label)DataList1.Items[i].FindControl("Label2");
 int post_id=Convert.ToInt32(id.Text.ToString());


使用它.


use it .


这篇关于如何访问数据列表标题中的页脚标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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