Click here to Skip to main content
15,914,221 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

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

My grid structure like this.
XML
<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>


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
Posted
Comments
Azee 3-Oct-13 7:28am    
where did you write the above code? and lblHrs is not in your footer template.
Santhosh23 3-Oct-13 7:39am    
yes, but how to access the itemtemplete label in FooterTemplate
What exactly you need? Do you need to access lblHrs or lblDetectHrs or lblPtohrs ?
Santhosh23 7-Oct-13 2:58am    
lblHrs
That is not inside Footer, so why are you searching it inside Footer?

lblHrs is not in your footer template. lblDetectHrs and lblPtohrs are.
 
Share this answer
 
Comments
Santhosh23 3-Oct-13 7:39am    
yes, but how to access the itemtemplete label in FooterTemplate
ZurdoDev 3-Oct-13 7:44am    
You can't. There isn't one. The item template is for records. The footer template defines what your footer looks like. They aren't the same thing.
Displaying Total in Footer of GridView[^]

Go through the link
C#
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 member="Tadit"]
Link text added to reflect the Article/QA title.
Corrected formatting and grammatical issues.
[/Edit]
 
Share this answer
 
v3
use repeater Item Databound event to find control in item template.

declare a string as global variable.
C#
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;
}

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

C#
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 thinks this may help you.
 
Share this answer
 
v3
Comments
OP has asked question on GridView not repeater.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900