Label & Code Behind

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I added a label server control in my aspx file. In the code behind, the IDE
does not generate the corresponding object like it does with buttons and
other objects.

What am I doing wrong? Is there a way to force the IDE to re-generate the
corresponding objects?

Appreciate your input.
J
 
I forgot to add the my code:

<asp:TemplateColumn HeaderText="Amount"
SortExpression="Amount">
<ItemTemplate>
<%# String.Format("{0:C}",
DataBinder.Eval(Container.DataItem, "Amount")) %>
</ItemTemplate>
<FooterTemplate>
<asp:Label Runat="server" ID="lblTotal">99.95</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
 
Hi,
You are not doing anything wrong !!!
Your label control is inside the FooterTemplete of DataGride. Means
Datagrid is the container of the Label. Thats why you will not see any
corresponding object in code behind.
If you want to access this Label control in your code, you need to use
FindControl method.

Thanks & Regards,

i9arcanes
 
Thank you very much. That explains it.

I have a quick question, sort of related to what I am trying to do. I am
basically trying to calculate the total of a column. However, on every
event, the value is "". Please help.

public void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
DoTotal(e.Item.Cells[5].Text);
e.Item.Cells[5].Text = string.Format("{0:C}",
Convert.ToDouble(e.Item.Cells[5].Text));
}
else if(e.Item.ItemType == ListItemType.Footer)
{
e.Item.Cells[4].Text="Total";
e.Item.Cells[5].Text = string.Format("{0:C}", m_dTotal);
}
}
 
I assume that m_Total variable is a private member variable of ur class !!
Please check you DoTotal() function. May be in this function you are
reinitializing the variable "m_dTotal" or may be you are assigning a value of
local variable to m_dTotal in DoTotal() function. Otherwise your code should
work...


thejackofall said:
Thank you very much. That explains it.

I have a quick question, sort of related to what I am trying to do. I am
basically trying to calculate the total of a column. However, on every
event, the value is "". Please help.

public void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
DoTotal(e.Item.Cells[5].Text);
e.Item.Cells[5].Text = string.Format("{0:C}",
Convert.ToDouble(e.Item.Cells[5].Text));
}
else if(e.Item.ItemType == ListItemType.Footer)
{
e.Item.Cells[4].Text="Total";
e.Item.Cells[5].Text = string.Format("{0:C}", m_dTotal);
}
}

i9arcanes said:
Hi,
You are not doing anything wrong !!!
Your label control is inside the FooterTemplete of DataGride. Means
Datagrid is the container of the Label. Thats why you will not see any
corresponding object in code behind.
If you want to access this Label control in your code, you need to use
FindControl method.

Thanks & Regards,

i9arcanes
 
No. My m_dTotal is initialized to 0.0f before the data is bound to the grid.
It's just that on every OnItemDataBound event, the expected data is not
there. The data for a date column is valid, but not the rest of the columns.

Thanks.
J

i9arcanes said:
I assume that m_Total variable is a private member variable of ur class !!
Please check you DoTotal() function. May be in this function you are
reinitializing the variable "m_dTotal" or may be you are assigning a value of
local variable to m_dTotal in DoTotal() function. Otherwise your code should
work...


thejackofall said:
Thank you very much. That explains it.

I have a quick question, sort of related to what I am trying to do. I am
basically trying to calculate the total of a column. However, on every
event, the value is "". Please help.

public void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
DoTotal(e.Item.Cells[5].Text);
e.Item.Cells[5].Text = string.Format("{0:C}",
Convert.ToDouble(e.Item.Cells[5].Text));
}
else if(e.Item.ItemType == ListItemType.Footer)
{
e.Item.Cells[4].Text="Total";
e.Item.Cells[5].Text = string.Format("{0:C}", m_dTotal);
}
}

i9arcanes said:
Hi,
You are not doing anything wrong !!!
Your label control is inside the FooterTemplete of DataGride. Means
Datagrid is the container of the Label. Thats why you will not see any
corresponding object in code behind.
If you want to access this Label control in your code, you need to use
FindControl method.

Thanks & Regards,

i9arcanes



:

I forgot to add the my code:

<asp:TemplateColumn HeaderText="Amount"
SortExpression="Amount">
<ItemTemplate>
<%# String.Format("{0:C}",
DataBinder.Eval(Container.DataItem, "Amount")) %>
</ItemTemplate>
<FooterTemplate>
<asp:Label Runat="server" ID="lblTotal">99.95</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>


:

I added a label server control in my aspx file. In the code behind, the IDE
does not generate the corresponding object like it does with buttons and
other objects.

What am I doing wrong? Is there a way to force the IDE to re-generate the
corresponding objects?

Appreciate your input.
J
 
No. My m_dTotal is initialized to 0.0f before the data is bound to the grid.
It's just that on every OnItemDataBound event, the expected data is not
there. The data for a date column is valid, but not the rest of the columns.

Thanks.
J

i9arcanes said:
I assume that m_Total variable is a private member variable of ur class !!
Please check you DoTotal() function. May be in this function you are
reinitializing the variable "m_dTotal" or may be you are assigning a value of
local variable to m_dTotal in DoTotal() function. Otherwise your code should
work...


thejackofall said:
Thank you very much. That explains it.

I have a quick question, sort of related to what I am trying to do. I am
basically trying to calculate the total of a column. However, on every
event, the value is "". Please help.

public void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
DoTotal(e.Item.Cells[5].Text);
e.Item.Cells[5].Text = string.Format("{0:C}",
Convert.ToDouble(e.Item.Cells[5].Text));
}
else if(e.Item.ItemType == ListItemType.Footer)
{
e.Item.Cells[4].Text="Total";
e.Item.Cells[5].Text = string.Format("{0:C}", m_dTotal);
}
}

i9arcanes said:
Hi,
You are not doing anything wrong !!!
Your label control is inside the FooterTemplete of DataGride. Means
Datagrid is the container of the Label. Thats why you will not see any
corresponding object in code behind.
If you want to access this Label control in your code, you need to use
FindControl method.

Thanks & Regards,

i9arcanes



:

I forgot to add the my code:

<asp:TemplateColumn HeaderText="Amount"
SortExpression="Amount">
<ItemTemplate>
<%# String.Format("{0:C}",
DataBinder.Eval(Container.DataItem, "Amount")) %>
</ItemTemplate>
<FooterTemplate>
<asp:Label Runat="server" ID="lblTotal">99.95</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>


:

I added a label server control in my aspx file. In the code behind, the IDE
does not generate the corresponding object like it does with buttons and
other objects.

What am I doing wrong? Is there a way to force the IDE to re-generate the
corresponding objects?

Appreciate your input.
J
 
Back
Top