如何在FooterRow模板中获取项模板标签值 [英] How to get the item template label value in FooterRow template

查看:53
本文介绍了如何在FooterRow模板中获取项模板标签值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有一个GV控件的网格视图控件,有ItemTemplate和FooterTemplate



我的网格结构如下。

Hi all,

I have one Grid-view Control in GV control having ItemTemplate and FooterTemplate

My grid structure like this.

<ItemTemplate>
<asp:Label ID="lblDisplayFromtime" runat="server" Text='<#Eval"DisplayFromTime")%>'></asp:Label>
    <asp:Label ID="lblDisplayTotime" runat="server" Text='<%#Eval("DisplayToTime")%>'></asp:Label>
    <asp:Label ID="lblPunchIsstatus" runat="server" Text='<%#Eval("PunchIsStatus") %>'  ></asp:Label>  
<asp:Label ID="lblHrs" runat="server"></asp:Label>                                                                                            </ItemTemplate>
                                                                                                                       <FooterTemplate>                                                                                                                                       <asp:Label ID="lblDetectHrs" runat="server"></asp:Label>                                                                                                                                       <asp:Label ID="lblPtohrs" runat="server"></asp:Label>                                                                                                                       </FooterTemplate>





我的问题是如何在footertemplate中获取itemTemplate标签值(lblhrs)

我的代码是这样的

if(e.Row.RowType == DataControlRowType.Footer)

{

Label lblnight =(标签)e.Row.FindControl(lblHrs);

}

但是它显示错误。没有设置对象引用。

如何获得标签值

请帮帮我。

谢谢和问候



my Qestions is how to get the itemTemplate Label value (lblhrs) in footertemplate
my code like this
if (e.Row.RowType == DataControlRowType.Footer)
{
Label lblnight = (Label)e.Row.FindControl("lblHrs");
}
but it shows Error. object references not set.
how to get the label value
please help me.
thanks and regards

推荐答案

lblHrs不在您的页脚模板中。 lblDetectHrs和lblPtohrs是。
lblHrs is not in your footer template. lblDetectHrs and lblPtohrs are.


显示GridView的页脚总数 [ ^ ]



浏览链接

Displaying Total in Footer of GridView[^]

Go through the link
float value=0;

if (e.Row.RowType == DataControlRowType.DataRow)
{

    Label lblhr = (Label)e.Row.FindControl("lblhrs");
    value+= float.Parse(lblhr.Text);
}

if (e.Row.RowType == DataControlRowType.Footer)
{
    Label cal = (Label)e.Row.FindControl("lblDetectHrs");

    System.Globalization.CultureInfo culin = new System.Globalization.CultureInfo("hi-IN", true);
    cal.Text = (value.ToString("C", culin)).Remove(0, 2).Trim();
 }









添加链接文本以反映文章/质量保证标题。

更正了格式和语法问题。

[/ Edit]


使用repeater Item Databound事件在项目模板中查找控件。



将字符串声明为全局变量。

use repeater Item Databound event to find control in item template.

declare a string as global variable.
string globalString = string.empty;

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
    Label lblName = new Label();
    lblName = (Label)e.Item.FindControl("lblName");
    globalString = lblName.Text;
}



这里的项目模板标签值存储在globalString中,现在找到页脚模板的控件,




Here the item templates label value is stored in globalString, Now find control of footer template,

if (repeater.Items.Count == 0)
{
    Label ltl = rptContacts.Controls[repeater.Controls.Count - 1].Controls[0].FindControl("Label") as Label ;

    if (ltl != null)
    {
        lt1.text = globalString;
    }
}





i认为这对你有帮助。



i thinks this may help you.


这篇关于如何在FooterRow模板中获取项模板标签值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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