By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,462 Members | 3,388 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,462 IT Pros & Developers. It's quick & easy.

Find footer labels in DataGrid

P: n/a
How do I find (and set) a couple of labels in the Footer after a DataGrid is
filled?

I have a bunch of DataGrids that get displayed nested inside a DataList.

The datagrid looks like:

************************************************** *****************************
<asp:DataGrid visible="False"
border=1
id="DataGrid1"
runat="server"
Width="400px"
Height="79px"
AutoGenerateColumns="False"
GridLines="None"
ShowFooter="true"
onItemDataBound="DataGrid1_ItemDataBound"
OnItemCommand="DataInsert"
onEditCommand="DataEdit"
onCancelCommand="DataCancel"
onUpdateCommand="DataUpdate">
<AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
BorderColor="White" BackColor="linen"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Answer">
<ItemTemplate>
<asp:Label id="lblAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:textbox id="txtAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:textbox>
</EditItemTemplate>
</asp:templateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblPositionID" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.PositionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblPositionIDFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblQuestionUnique" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblQuestionUniqueFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="AnswerUnique" visible="false" ReadOnly="true"
HeaderText="AnswerUnique"></asp:BoundColumn>
<asp:EditCommandColumn EditText="<img src='..\images\Edit.png'border='0'
id='textbox1'>" visible="true"
ButtonType="LinkButton"
UpdateText="<img src='..\images\update.png' border='0'>"
CancelText="<img src='..\images\Cancel.png' border='0'>" />
<asp:TemplateColumn >
<FooterTemplate>
<asp:LinkButton CommandName="Insert" Text="<img
src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton CommandName="Delete" Text="<img
src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
************************************************** *************************************

I have the DataGrid by doing something like:

for each oItem as DataListItem in DataList1.Items
Dim oGrid as DataGrid = CType(oItem.FindControl("DataGrid1"),DataGrid)

How would I use oGrid to find and set "lblPositionIDFooter" and
"lblQuestionUniqueFooter"?

I need this as I need a place to put the PositionID and QuestionUnique as
they are keys I need to use in my Insert statement. I am inserting rows
from the Footer and need to get these variables from some where, so this
seems to be the most logical place to store them.

Thanks,

Tom.
Nov 18 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Try: e.Item.FindControl("lblPositionIDFooter)

Sonu

-----Original Message-----
How do I find (and set) a couple of labels in the Footer after a DataGrid isfilled?

I have a bunch of DataGrids that get displayed nested inside a DataList.
The datagrid looks like:

************************************************* ********* *********************<asp:DataGrid visible="False"
border=1
id="DataGrid1"
runat="server"
Width="400px"
Height="79px"
AutoGenerateColumns="False"
GridLines="None"
ShowFooter="true"
onItemDataBound="DataGrid1_ItemDataBound"
OnItemCommand="DataInsert"
onEditCommand="DataEdit"
onCancelCommand="DataCancel"
onUpdateCommand="DataUpdate">
<AlternatingItemStyle BorderWidth="0px" BorderStyle="None"BorderColor="White" BackColor="linen"></AlternatingItemStyle> <HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle> <Columns>
<asp:TemplateColumn HeaderText="Answer">
<ItemTemplate>
<asp:Label id="lblAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox> </FooterTemplate>
<EditItemTemplate>
<asp:textbox id="txtAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:textbox>
</EditItemTemplate>
</asp:templateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblPositionID" runat="server" Text='<% #DataBinder.Eval(Container, "DataItem.PositionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblPositionIDFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblQuestionUnique" runat="server" Text='<%#DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblQuestionUniqueFooter" runat="server"> </asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="AnswerUnique" visible="false" ReadOnly="true"HeaderText="AnswerUnique"></asp:BoundColumn>
<asp:EditCommandColumn EditText="<img src='..\images\Edit.png'border='0'id='textbox1'>" visible="true"
ButtonType="LinkButton"
UpdateText="<img src='..\images\update.png' border='0'>"CancelText="<img src='..\images\Cancel.png' border='0'>" /> <asp:TemplateColumn >
<FooterTemplate>
<asp:LinkButton CommandName="Insert" Text="<img
src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" /> </FooterTemplate>
<ItemTemplate>
<asp:LinkButton CommandName="Delete" Text="<img
src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" /> </ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
************************************************* ********* *****************************
I have the DataGrid by doing something like:

for each oItem as DataListItem in DataList1.Items
Dim oGrid as DataGrid = CType(oItem.FindControl ("DataGrid1"),DataGrid)
How would I use oGrid to find and set "lblPositionIDFooter" and"lblQuestionUniqueFooter"?

I need this as I need a place to put the PositionID and QuestionUnique asthey are keys I need to use in my Insert statement. I am inserting rowsfrom the Footer and need to get these variables from some where, so thisseems to be the most logical place to store them.

Thanks,

Tom.
.

Nov 18 '05 #2

P: n/a
First you need to check whether that datagrid item is footer, then you can
use e.item.cells(<correspondingcell index>.findcontrol(<your control name>)
method to find your label control. For more details, refer this link
http://www.extremeexperts.com/Net/Ar...stoFooter.aspx

--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"tshad" <ts**********@ftsolutions.com> wrote in message
news:OU**************@TK2MSFTNGP09.phx.gbl...
How do I find (and set) a couple of labels in the Footer after a DataGrid is filled?

I have a bunch of DataGrids that get displayed nested inside a DataList.

The datagrid looks like:

************************************************** **************************
*** <asp:DataGrid visible="False"
border=1
id="DataGrid1"
runat="server"
Width="400px"
Height="79px"
AutoGenerateColumns="False"
GridLines="None"
ShowFooter="true"
onItemDataBound="DataGrid1_ItemDataBound"
OnItemCommand="DataInsert"
onEditCommand="DataEdit"
onCancelCommand="DataCancel"
onUpdateCommand="DataUpdate">
<AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
BorderColor="White" BackColor="linen"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Answer">
<ItemTemplate>
<asp:Label id="lblAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:textbox id="txtAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:textbox>
</EditItemTemplate>
</asp:templateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblPositionID" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.PositionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblPositionIDFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblQuestionUnique" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblQuestionUniqueFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="AnswerUnique" visible="false" ReadOnly="true" HeaderText="AnswerUnique"></asp:BoundColumn>
<asp:EditCommandColumn EditText="<img src='..\images\Edit.png'border='0'
id='textbox1'>" visible="true"
ButtonType="LinkButton"
UpdateText="<img src='..\images\update.png' border='0'>"
CancelText="<img src='..\images\Cancel.png' border='0'>" />
<asp:TemplateColumn >
<FooterTemplate>
<asp:LinkButton CommandName="Insert" Text="<img
src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton CommandName="Delete" Text="<img
src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
************************************************** **************************
***********
I have the DataGrid by doing something like:

for each oItem as DataListItem in DataList1.Items
Dim oGrid as DataGrid = CType(oItem.FindControl("DataGrid1"),DataGrid)

How would I use oGrid to find and set "lblPositionIDFooter" and
"lblQuestionUniqueFooter"?

I need this as I need a place to put the PositionID and QuestionUnique as
they are keys I need to use in my Insert statement. I am inserting rows
from the Footer and need to get these variables from some where, so this
seems to be the most logical place to store them.

Thanks,

Tom.

Nov 18 '05 #3

P: n/a
Hi tshad:

You might want to try during the ItemDataBound event instead (check
for e.Item.ItemType == ListItemType.Footer).

If you need to wait until afterwards, then you can index into the
Controls collection of the grid. (The Items collection might look
tempting at first, but it only contains DataGridItems bound to
records, the header and footer items appear only in the Controls
collection). The footer item should be in the last element of the
Controls array.

I have some examples about 1/2 through this article:
http://www.odetocode.com/Articles/116.aspx

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/


On Tue, 2 Nov 2004 17:14:06 -0800, "tshad"
<ts**********@ftsolutions.com> wrote:
How do I find (and set) a couple of labels in the Footer after a DataGrid is
filled?

I have a bunch of DataGrids that get displayed nested inside a DataList.

The datagrid looks like:

************************************************* ******************************
<asp:DataGrid visible="False"
border=1
id="DataGrid1"
runat="server"
Width="400px"
Height="79px"
AutoGenerateColumns="False"
GridLines="None"
ShowFooter="true"
onItemDataBound="DataGrid1_ItemDataBound"
OnItemCommand="DataInsert"
onEditCommand="DataEdit"
onCancelCommand="DataCancel"
onUpdateCommand="DataUpdate">
<AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
BorderColor="White" BackColor="linen"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Answer">
<ItemTemplate>
<asp:Label id="lblAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:textbox id="txtAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:textbox>
</EditItemTemplate>
</asp:templateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblPositionID" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.PositionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblPositionIDFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblQuestionUnique" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblQuestionUniqueFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="AnswerUnique" visible="false" ReadOnly="true"
HeaderText="AnswerUnique"></asp:BoundColumn>
<asp:EditCommandColumn EditText="<img src='..\images\Edit.png'border='0'
id='textbox1'>" visible="true"
ButtonType="LinkButton"
UpdateText="<img src='..\images\update.png' border='0'>"
CancelText="<img src='..\images\Cancel.png' border='0'>" />
<asp:TemplateColumn >
<FooterTemplate>
<asp:LinkButton CommandName="Insert" Text="<img
src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton CommandName="Delete" Text="<img
src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
************************************************* **************************************

I have the DataGrid by doing something like:

for each oItem as DataListItem in DataList1.Items
Dim oGrid as DataGrid = CType(oItem.FindControl("DataGrid1"),DataGrid)

How would I use oGrid to find and set "lblPositionIDFooter" and
"lblQuestionUniqueFooter"?

I need this as I need a place to put the PositionID and QuestionUnique as
they are keys I need to use in my Insert statement. I am inserting rows
from the Footer and need to get these variables from some where, so this
seems to be the most logical place to store them.

Thanks,

Tom.


Nov 18 '05 #4

P: n/a
"Sonu Kapoor" <so********@gmail.com> wrote in message
news:39****************************@phx.gbl...
Try: e.Item.FindControl("lblPositionIDFooter)
I can't use e.item as the object is a datalist that has a datagrid in it. I
then find the oGrid from that.

So I tried:

Dim fPositionID as Label = oGrid.Item.FindControl("lblPositionIDFooter")

and got the following error message:
************************************************
Compiler Error Message: BC30456: 'Item' is not a member of
'System.Web.UI.WebControls.DataGrid'.

Source Error:

Line 225: Dim oCollapse as ImageButton =
CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("CollapseButton")
,ImageButton)
Line 226:
Line 227: Dim fPositionID as Label =
oGrid.Item.FindControl("lblPositionIDFooter")
************************************************** ***************

Tom.
Sonu

-----Original Message-----
How do I find (and set) a couple of labels in the Footer

after a DataGrid is
filled?

I have a bunch of DataGrids that get displayed nested

inside a DataList.

The datagrid looks like:

************************************************* *********

*********************
<asp:DataGrid visible="False"
border=1
id="DataGrid1"
runat="server"
Width="400px"
Height="79px"
AutoGenerateColumns="False"
GridLines="None"
ShowFooter="true"
onItemDataBound="DataGrid1_ItemDataBound"
OnItemCommand="DataInsert"
onEditCommand="DataEdit"
onCancelCommand="DataCancel"
onUpdateCommand="DataUpdate">
<AlternatingItemStyle BorderWidth="0px"

BorderStyle="None"
BorderColor="White"

BackColor="linen"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True"

BackColor="#6699cc"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Answer">
<ItemTemplate>
<asp:Label id="lblAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAnswerFooter"

runat="server"></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:textbox id="txtAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:textbox>
</EditItemTemplate>
</asp:templateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblPositionID" runat="server" Text='<%

#
DataBinder.Eval(Container, "DataItem.PositionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblPositionIDFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblQuestionUnique" runat="server"

Text='<%#
DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblQuestionUniqueFooter"

runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="AnswerUnique"

visible="false" ReadOnly="true"
HeaderText="AnswerUnique"></asp:BoundColumn>
<asp:EditCommandColumn EditText="<img

src='..\images\Edit.png'border='0'
id='textbox1'>" visible="true"
ButtonType="LinkButton"
UpdateText="<img src='..\images\update.png'

border='0'>"
CancelText="<img src='..\images\Cancel.png'

border='0'>" />
<asp:TemplateColumn >
<FooterTemplate>
<asp:LinkButton CommandName="Insert" Text="<img
src='..\images\Add.gif'border='0'>" ID="btnAdd"

Runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton CommandName="Delete" Text="<img
src='..\images\Delete.gif'border='0'>" ID="btnDel"

Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
************************************************* *********

*****************************

I have the DataGrid by doing something like:

for each oItem as DataListItem in DataList1.Items
Dim oGrid as DataGrid = CType(oItem.FindControl

("DataGrid1"),DataGrid)

How would I use oGrid to find and

set "lblPositionIDFooter" and
"lblQuestionUniqueFooter"?

I need this as I need a place to put the PositionID and

QuestionUnique as
they are keys I need to use in my Insert statement. I am

inserting rows
from the Footer and need to get these variables from some

where, so this
seems to be the most logical place to store them.

Thanks,

Tom.
.

Nov 18 '05 #5

P: n/a
"Saravana" <sa******@sct.co.in> wrote in message
news:yD****************@news.cpqcorp.net...
First you need to check whether that datagrid item is footer, then you can
use e.item.cells(<correspondingcell index>.findcontrol(<your control name>) method to find your label control. For more details, refer this link
http://www.extremeexperts.com/Net/Ar...stoFooter.aspx
I already know I have a footer and I have the Grid object. I just don't
know how to get to a label that is already in the footer.

Tom.
--
Saravana
http://dotnetjunkies.com/WebLog/saravana/
www.ExtremeExperts.com
"tshad" <ts**********@ftsolutions.com> wrote in message
news:OU**************@TK2MSFTNGP09.phx.gbl...
How do I find (and set) a couple of labels in the Footer after a DataGrid
is
filled?

I have a bunch of DataGrids that get displayed nested inside a DataList.

The datagrid looks like:

************************************************** ************************** ***
<asp:DataGrid visible="False"
border=1
id="DataGrid1"
runat="server"
Width="400px"
Height="79px"
AutoGenerateColumns="False"
GridLines="None"
ShowFooter="true"
onItemDataBound="DataGrid1_ItemDataBound"
OnItemCommand="DataInsert"
onEditCommand="DataEdit"
onCancelCommand="DataCancel"
onUpdateCommand="DataUpdate">
<AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
BorderColor="White" BackColor="linen"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Answer">
<ItemTemplate>
<asp:Label id="lblAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:textbox id="txtAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:textbox>
</EditItemTemplate>
</asp:templateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblPositionID" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.PositionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblPositionIDFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblQuestionUnique" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblQuestionUniqueFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="AnswerUnique" visible="false" ReadOnly="true"
HeaderText="AnswerUnique"></asp:BoundColumn>
<asp:EditCommandColumn EditText="<img

src='..\images\Edit.png'border='0' id='textbox1'>" visible="true"
ButtonType="LinkButton"
UpdateText="<img src='..\images\update.png' border='0'>"
CancelText="<img src='..\images\Cancel.png' border='0'>" />
<asp:TemplateColumn >
<FooterTemplate>
<asp:LinkButton CommandName="Insert" Text="<img
src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton CommandName="Delete" Text="<img
src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>

************************************************** ************************** ***********

I have the DataGrid by doing something like:

for each oItem as DataListItem in DataList1.Items
Dim oGrid as DataGrid = CType(oItem.FindControl("DataGrid1"),DataGrid)
How would I use oGrid to find and set "lblPositionIDFooter" and
"lblQuestionUniqueFooter"?

I need this as I need a place to put the PositionID and QuestionUnique as they are keys I need to use in my Insert statement. I am inserting rows
from the Footer and need to get these variables from some where, so this
seems to be the most logical place to store them.

Thanks,

Tom.


Nov 18 '05 #6

P: n/a
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:og********************************@4ax.com...
Hi tshad:

You might want to try during the ItemDataBound event instead (check
for e.Item.ItemType == ListItemType.Footer).

If you need to wait until afterwards, then you can index into the
Controls collection of the grid. (The Items collection might look
tempting at first, but it only contains DataGridItems bound to
records, the header and footer items appear only in the Controls
collection). The footer item should be in the last element of the
Controls array.

I have some examples about 1/2 through this article:
http://www.odetocode.com/Articles/116.aspx
I tried some of what you had and here is what I came up with.

The routine where I need to get access to the label in the footer is:

************************************************** ********************
Sub OnSelectIndexChanged(sender as Object,e as DataListCommandEventArgs)
if e.CommandName = "Select" then
DataList1.SelectedIndex = e.Item.ItemIndex
end if

Dim oGrid as DataGrid =
CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DataGrid1"),Data
Grid)

Dim lblPositionIDF as Label =
oGrid.Controls(0).Controls(0).FindControl("lblPosi tionIDFooter")
************************************************** ********************

Gives me the following error:

Specified argument was out of the range of valid values. Parameter name:
index

The DataGrid footer section looks like:

************************************************** ********************
<asp:TemplateColumn visible="true">
<ItemTemplate>
<asp:Label id="lblPositionID" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.PositionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblPositionIDFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
************************************************** ********************

This doesn't seem to be it, unless I am missing something (and I probably
am).

Thanks,

Tom.

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/


On Tue, 2 Nov 2004 17:14:06 -0800, "tshad"
<ts**********@ftsolutions.com> wrote:
How do I find (and set) a couple of labels in the Footer after a DataGrid isfilled?

I have a bunch of DataGrids that get displayed nested inside a DataList.

The datagrid looks like:


************************************************* **************************

****
<asp:DataGrid visible="False"
border=1
id="DataGrid1"
runat="server"
Width="400px"
Height="79px"
AutoGenerateColumns="False"
GridLines="None"
ShowFooter="true"
onItemDataBound="DataGrid1_ItemDataBound"
OnItemCommand="DataInsert"
onEditCommand="DataEdit"
onCancelCommand="DataCancel"
onUpdateCommand="DataUpdate">
<AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
BorderColor="White" BackColor="linen"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Answer">
<ItemTemplate>
<asp:Label id="lblAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:textbox id="txtAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:textbox>
</EditItemTemplate>
</asp:templateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblPositionID" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.PositionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblPositionIDFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblQuestionUnique" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblQuestionUniqueFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="AnswerUnique" visible="false" ReadOnly="true"HeaderText="AnswerUnique"></asp:BoundColumn>
<asp:EditCommandColumn EditText="<img src='..\images\Edit.png'border='0'id='textbox1'>" visible="true"
ButtonType="LinkButton"
UpdateText="<img src='..\images\update.png' border='0'>"
CancelText="<img src='..\images\Cancel.png' border='0'>" />
<asp:TemplateColumn >
<FooterTemplate>
<asp:LinkButton CommandName="Insert" Text="<img
src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton CommandName="Delete" Text="<img
src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>


************************************************* **************************

************

I have the DataGrid by doing something like:

for each oItem as DataListItem in DataList1.Items
Dim oGrid as DataGrid = CType(oItem.FindControl("DataGrid1"),DataGrid)
How would I use oGrid to find and set "lblPositionIDFooter" and
"lblQuestionUniqueFooter"?

I need this as I need a place to put the PositionID and QuestionUnique as
they are keys I need to use in my Insert statement. I am inserting rows
from the Footer and need to get these variables from some where, so this
seems to be the most logical place to store them.

Thanks,

Tom.

Nov 18 '05 #7

P: n/a
tshad,

After a week or two of trying to solve a similar issue, I stumbles upon your
post.

Alleluia! I believe I am on my way to solving my problem. I'll post back in
a couple of hours and let you know if this really was it.

I have a datagrid with 2 nested datagrids. Here is a screenshot.
http://www.smartbizniz.com/ee/SBS_Va..._EE_Sample.pdf

I am using the footers of the nested datagrids to add new records. It was
easy for the users to push the Add link to add records one by one. They got
tired of that and wanted to add new records a page at a time.

I could loop through the records in the master datagrid and get at the
nested datagrid but I couldn't figure out how to get the values in the nested
datagrid's footer. Now I have it:

Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnTest.Click

Dim strText As String

For Each item As DataGridItem In DataGrid1.Items

Dim dgTemp As DataGrid = CType(item.FindControl("DataGrid_PTD"),
DataGrid)
Dim txt As TextBox =
CType(dgTemp.Controls(0).Controls(1).FindControl(" txtPTDsNarrativeAdd"),
TextBox)
If txt Is Nothing Then
strText = ""
Else
strText = txt.Text
End If

'Now add a new record to the dataset
Next

End Sub

Have you been able to solve your problem?

"tshad" wrote:
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:og********************************@4ax.com...
Hi tshad:

You might want to try during the ItemDataBound event instead (check
for e.Item.ItemType == ListItemType.Footer).

If you need to wait until afterwards, then you can index into the
Controls collection of the grid. (The Items collection might look
tempting at first, but it only contains DataGridItems bound to
records, the header and footer items appear only in the Controls
collection). The footer item should be in the last element of the
Controls array.

I have some examples about 1/2 through this article:
http://www.odetocode.com/Articles/116.aspx


I tried some of what you had and here is what I came up with.

The routine where I need to get access to the label in the footer is:

************************************************** ********************
Sub OnSelectIndexChanged(sender as Object,e as DataListCommandEventArgs)
if e.CommandName = "Select" then
DataList1.SelectedIndex = e.Item.ItemIndex
end if

Dim oGrid as DataGrid =
CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DataGrid1"),Data
Grid)

Dim lblPositionIDF as Label =
oGrid.Controls(0).Controls(0).FindControl("lblPosi tionIDFooter")
************************************************** ********************

Gives me the following error:

Specified argument was out of the range of valid values. Parameter name:
index

The DataGrid footer section looks like:

************************************************** ********************
<asp:TemplateColumn visible="true">
<ItemTemplate>
<asp:Label id="lblPositionID" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.PositionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblPositionIDFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
************************************************** ********************

This doesn't seem to be it, unless I am missing something (and I probably
am).

Thanks,

Tom.

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/


On Tue, 2 Nov 2004 17:14:06 -0800, "tshad"
<ts**********@ftsolutions.com> wrote:
How do I find (and set) a couple of labels in the Footer after a DataGrid isfilled?

I have a bunch of DataGrids that get displayed nested inside a DataList.

The datagrid looks like:


************************************************* **************************

****
<asp:DataGrid visible="False"
border=1
id="DataGrid1"
runat="server"
Width="400px"
Height="79px"
AutoGenerateColumns="False"
GridLines="None"
ShowFooter="true"
onItemDataBound="DataGrid1_ItemDataBound"
OnItemCommand="DataInsert"
onEditCommand="DataEdit"
onCancelCommand="DataCancel"
onUpdateCommand="DataUpdate">
<AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
BorderColor="White" BackColor="linen"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Answer">
<ItemTemplate>
<asp:Label id="lblAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:textbox id="txtAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:textbox>
</EditItemTemplate>
</asp:templateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblPositionID" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.PositionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblPositionIDFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblQuestionUnique" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblQuestionUniqueFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="AnswerUnique" visible="false" ReadOnly="true"HeaderText="AnswerUnique"></asp:BoundColumn>
<asp:EditCommandColumn EditText="<img src='..\images\Edit.png'border='0'id='textbox1'>" visible="true"
ButtonType="LinkButton"
UpdateText="<img src='..\images\update.png' border='0'>"
CancelText="<img src='..\images\Cancel.png' border='0'>" />
<asp:TemplateColumn >
<FooterTemplate>
<asp:LinkButton CommandName="Insert" Text="<img
src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton CommandName="Delete" Text="<img
src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>


************************************************* **************************

************

I have the DataGrid by doing something like:

for each oItem as DataListItem in DataList1.Items
Dim oGrid as DataGrid = CType(oItem.FindControl("DataGrid1"),DataGrid)
How would I use oGrid to find and set "lblPositionIDFooter" and
"lblQuestionUniqueFooter"?

I need this as I need a place to put the PositionID and QuestionUnique as
they are keys I need to use in my Insert statement. I am inserting rows
from the Footer and need to get these variables from some where, so this
seems to be the most logical place to store them.

Thanks,

Tom.


Nov 18 '05 #8

P: n/a
tshad:

This was it!

It took a little while for me to realize that the index for the footer
control changes depending on how many records are in the datagrid. However,
in my case it is always the last control.

Hope you were able to solve your problem.

Here is my code:

Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnTest.Click

Dim strNarrativePTD As String
Dim strNarrativeYTD As String
Dim intFooterPTD As Integer
Dim intFooterYTD As Integer
Dim intNarrativeType As Int16
Dim intSortOrder As Integer = 1 'Sort order has not been implemented yet

For Each item As DataGridItem In DataGrid1.Items

Dim dgPTD As DataGrid = CType(item.FindControl("DataGrid_PTD"),
DataGrid)
Dim dgYTD As DataGrid = CType(item.FindControl("DataGrid_YTD"),
DataGrid)

'The Footer section is the last control in the nested datagrid. We
will use this index later.
intFooterPTD = dgPTD.Controls(0).Controls.Count - 1
intFooterYTD = dgYTD.Controls(0).Controls.Count - 1

'First check the PTD Comments
Dim txtPTD As TextBox =
CType(dgPTD.Controls(0).Controls(intFooterPTD).Fin dControl("txtPTDsNarrativeAdd"), TextBox)
Dim lblPTD As Label =
CType(dgPTD.Controls(0).Controls(intFooterPTD).Fin dControl("lblhAcctPTDAdd"),
Label)
If txtPTD Is Nothing Then
strNarrativePTD = ""
Else
strNarrativePTD = txtPTD.Text
strHAcct = lblPTD.Text
intNarrativeType = 1
End If

'If there is something in the textbox, add the record.
If Len(strNarrativePTD) > 0 Then
NarrativesAdd(intNarrativeType, strNarrativePTD, intSortOrder)
End If

'Second check the YTD Comments
Dim txtYTD As TextBox =
CType(dgYTD.Controls(0).Controls(intFooterYTD).Fin dControl("txtYTDsNarrativeAdd"), TextBox)
Dim lblYTD As Label =
CType(dgYTD.Controls(0).Controls(intFooterYTD).Fin dControl("lblhAcctYTDAdd"),
Label)
If txtYTD Is Nothing Then
strNarrativeYTD = ""
Else
strNarrativeYTD = txtYTD.Text
strHAcct = lblYTD.Text
intNarrativeType = 12
End If

'If there is something in the textbox, add the record.
If Len(strNarrativeYTD) > 0 Then
NarrativesAdd(intNarrativeType, strNarrativeYTD, intSortOrder)
End If

Next

LoadGrid()

End Sub

"tshad" wrote:
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:og********************************@4ax.com...
Hi tshad:

You might want to try during the ItemDataBound event instead (check
for e.Item.ItemType == ListItemType.Footer).

If you need to wait until afterwards, then you can index into the
Controls collection of the grid. (The Items collection might look
tempting at first, but it only contains DataGridItems bound to
records, the header and footer items appear only in the Controls
collection). The footer item should be in the last element of the
Controls array.

I have some examples about 1/2 through this article:
http://www.odetocode.com/Articles/116.aspx


I tried some of what you had and here is what I came up with.

The routine where I need to get access to the label in the footer is:

************************************************** ********************
Sub OnSelectIndexChanged(sender as Object,e as DataListCommandEventArgs)
if e.CommandName = "Select" then
DataList1.SelectedIndex = e.Item.ItemIndex
end if

Dim oGrid as DataGrid =
CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DataGrid1"),Data
Grid)

Dim lblPositionIDF as Label =
oGrid.Controls(0).Controls(0).FindControl("lblPosi tionIDFooter")
************************************************** ********************

Gives me the following error:

Specified argument was out of the range of valid values. Parameter name:
index

The DataGrid footer section looks like:

************************************************** ********************
<asp:TemplateColumn visible="true">
<ItemTemplate>
<asp:Label id="lblPositionID" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.PositionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblPositionIDFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
************************************************** ********************

This doesn't seem to be it, unless I am missing something (and I probably
am).

Thanks,

Tom.

HTH,

--
Scott
http://www.OdeToCode.com/blogs/scott/


On Tue, 2 Nov 2004 17:14:06 -0800, "tshad"
<ts**********@ftsolutions.com> wrote:
How do I find (and set) a couple of labels in the Footer after a DataGrid isfilled?

I have a bunch of DataGrids that get displayed nested inside a DataList.

The datagrid looks like:


************************************************* **************************

****
<asp:DataGrid visible="False"
border=1
id="DataGrid1"
runat="server"
Width="400px"
Height="79px"
AutoGenerateColumns="False"
GridLines="None"
ShowFooter="true"
onItemDataBound="DataGrid1_ItemDataBound"
OnItemCommand="DataInsert"
onEditCommand="DataEdit"
onCancelCommand="DataCancel"
onUpdateCommand="DataUpdate">
<AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
BorderColor="White" BackColor="linen"></AlternatingItemStyle>
<HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Answer">
<ItemTemplate>
<asp:Label id="lblAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
</FooterTemplate>
<EditItemTemplate>
<asp:textbox id="txtAnswer" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Answer") %>'>
</asp:textbox>
</EditItemTemplate>
</asp:templateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblPositionID" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.PositionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblPositionIDFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn >
<ItemTemplate>
<asp:Label id="lblQuestionUnique" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblQuestionUniqueFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="AnswerUnique" visible="false" ReadOnly="true"HeaderText="AnswerUnique"></asp:BoundColumn>
<asp:EditCommandColumn EditText="<img src='..\images\Edit.png'border='0'id='textbox1'>" visible="true"
ButtonType="LinkButton"
UpdateText="<img src='..\images\update.png' border='0'>"
CancelText="<img src='..\images\Cancel.png' border='0'>" />
<asp:TemplateColumn >
<FooterTemplate>
<asp:LinkButton CommandName="Insert" Text="<img
src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
</FooterTemplate>
<ItemTemplate>
<asp:LinkButton CommandName="Delete" Text="<img
src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>


************************************************* **************************

************

I have the DataGrid by doing something like:

for each oItem as DataListItem in DataList1.Items
Dim oGrid as DataGrid = CType(oItem.FindControl("DataGrid1"),DataGrid)
How would I use oGrid to find and set "lblPositionIDFooter" and
"lblQuestionUniqueFooter"?

I need this as I need a place to put the PositionID and QuestionUnique as
they are keys I need to use in my Insert statement. I am inserting rows
from the Footer and need to get these variables from some where, so this
seems to be the most logical place to store them.

Thanks,

Tom.


Nov 18 '05 #9

P: n/a
"John Desautels" <John De*******@discussions.microsoft.com> wrote in message
news:C4**********************************@microsof t.com...
tshad:

This was it!

It took a little while for me to realize that the index for the footer
control changes depending on how many records are in the datagrid.
However,
in my case it is always the last control.

Hope you were able to solve your problem.
Actually,

I did. But not the way I wanted to.

The problem was I have multiple grids inside of a datalist. Each grid was a
different set up records differentiated by a unique number. My problem is
finding out what the unique number was.

I figured I would just look through the datalist until I find the datagrid
that matched the name of the one I was using. I know that the table ID's
would be different when the page was rendered. What I didn't realize that
in ASP, before it is rendered, all the ID's are identical. So that didn't
work.

What I ended up doing was puting the unique number in a hidden column on the
footer as the table was being populated. Then when I did the insert I would
already be pointing at the Footer and I could get the data easily at that
point.

What I haven't been able to do was figure out how to find out which Datalist
row (the parent) is equated with the Datagrid I am working with. I assume I
will have the same problem - same name.

Thanks,

Tom.
Here is my code:

Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnTest.Click

Dim strNarrativePTD As String
Dim strNarrativeYTD As String
Dim intFooterPTD As Integer
Dim intFooterYTD As Integer
Dim intNarrativeType As Int16
Dim intSortOrder As Integer = 1 'Sort order has not been implemented
yet

For Each item As DataGridItem In DataGrid1.Items

Dim dgPTD As DataGrid = CType(item.FindControl("DataGrid_PTD"),
DataGrid)
Dim dgYTD As DataGrid = CType(item.FindControl("DataGrid_YTD"),
DataGrid)

'The Footer section is the last control in the nested datagrid. We
will use this index later.
intFooterPTD = dgPTD.Controls(0).Controls.Count - 1
intFooterYTD = dgYTD.Controls(0).Controls.Count - 1

'First check the PTD Comments
Dim txtPTD As TextBox =
CType(dgPTD.Controls(0).Controls(intFooterPTD).Fin dControl("txtPTDsNarrativeAdd"),
TextBox)
Dim lblPTD As Label =
CType(dgPTD.Controls(0).Controls(intFooterPTD).Fin dControl("lblhAcctPTDAdd"),
Label)
If txtPTD Is Nothing Then
strNarrativePTD = ""
Else
strNarrativePTD = txtPTD.Text
strHAcct = lblPTD.Text
intNarrativeType = 1
End If

'If there is something in the textbox, add the record.
If Len(strNarrativePTD) > 0 Then
NarrativesAdd(intNarrativeType, strNarrativePTD, intSortOrder)
End If

'Second check the YTD Comments
Dim txtYTD As TextBox =
CType(dgYTD.Controls(0).Controls(intFooterYTD).Fin dControl("txtYTDsNarrativeAdd"),
TextBox)
Dim lblYTD As Label =
CType(dgYTD.Controls(0).Controls(intFooterYTD).Fin dControl("lblhAcctYTDAdd"),
Label)
If txtYTD Is Nothing Then
strNarrativeYTD = ""
Else
strNarrativeYTD = txtYTD.Text
strHAcct = lblYTD.Text
intNarrativeType = 12
End If

'If there is something in the textbox, add the record.
If Len(strNarrativeYTD) > 0 Then
NarrativesAdd(intNarrativeType, strNarrativeYTD, intSortOrder)
End If

Next

LoadGrid()

End Sub

"tshad" wrote:
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:og********************************@4ax.com...
> Hi tshad:
>
> You might want to try during the ItemDataBound event instead (check
> for e.Item.ItemType == ListItemType.Footer).
>
> If you need to wait until afterwards, then you can index into the
> Controls collection of the grid. (The Items collection might look
> tempting at first, but it only contains DataGridItems bound to
> records, the header and footer items appear only in the Controls
> collection). The footer item should be in the last element of the
> Controls array.
>
> I have some examples about 1/2 through this article:
> http://www.odetocode.com/Articles/116.aspx


I tried some of what you had and here is what I came up with.

The routine where I need to get access to the label in the footer is:

************************************************** ********************
Sub OnSelectIndexChanged(sender as Object,e as DataListCommandEventArgs)
if e.CommandName = "Select" then
DataList1.SelectedIndex = e.Item.ItemIndex
end if

Dim oGrid as DataGrid =
CType(DataList1.Items(DataList1.SelectedIndex).Fin dControl("DataGrid1"),Data
Grid)

Dim lblPositionIDF as Label =
oGrid.Controls(0).Controls(0).FindControl("lblPosi tionIDFooter")
************************************************** ********************

Gives me the following error:

Specified argument was out of the range of valid values. Parameter name:
index

The DataGrid footer section looks like:

************************************************** ********************
<asp:TemplateColumn visible="true">
<ItemTemplate>
<asp:Label id="lblPositionID" runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.PositionID") %>'>
</asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label id="lblPositionIDFooter" runat="server">
</asp:Label>
</FooterTemplate>
</asp:TemplateColumn>
************************************************** ********************

This doesn't seem to be it, unless I am missing something (and I probably
am).

Thanks,

Tom.
>
> HTH,
>
> --
> Scott
> http://www.OdeToCode.com/blogs/scott/
>
>
>
>
> On Tue, 2 Nov 2004 17:14:06 -0800, "tshad"
> <ts**********@ftsolutions.com> wrote:
>
> >How do I find (and set) a couple of labels in the Footer after a
> >DataGrid

is
> >filled?
> >
> >I have a bunch of DataGrids that get displayed nested inside a
> >DataList.
> >
> >The datagrid looks like:
> >
>
>************************************************* **************************

****
> ><asp:DataGrid visible="False"
> > border=1
> > id="DataGrid1"
> > runat="server"
> > Width="400px"
> > Height="79px"
> > AutoGenerateColumns="False"
> > GridLines="None"
> > ShowFooter="true"
> > onItemDataBound="DataGrid1_ItemDataBound"
> > OnItemCommand="DataInsert"
> > onEditCommand="DataEdit"
> > onCancelCommand="DataCancel"
> > onUpdateCommand="DataUpdate">
> > <AlternatingItemStyle BorderWidth="0px" BorderStyle="None"
> >BorderColor="White" BackColor="linen"></AlternatingItemStyle>
> > <HeaderStyle Font-Bold="True" BackColor="#6699cc"></HeaderStyle>
> > <Columns>
> > <asp:TemplateColumn HeaderText="Answer">
> > <ItemTemplate>
> > <asp:Label id="lblAnswer" runat="server" Text='<%#
> >DataBinder.Eval(Container, "DataItem.Answer") %>'>
> > </asp:Label>
> > </ItemTemplate>
> > <FooterTemplate>
> > <asp:TextBox id="txtAnswerFooter" runat="server"></asp:TextBox>
> > </FooterTemplate>
> > <EditItemTemplate>
> > <asp:textbox id="txtAnswer" runat="server" Text='<%#
> >DataBinder.Eval(Container, "DataItem.Answer") %>'>
> > </asp:textbox>
> > </EditItemTemplate>
> > </asp:templateColumn>
> > <asp:TemplateColumn >
> > <ItemTemplate>
> > <asp:Label id="lblPositionID" runat="server" Text='<%#
> >DataBinder.Eval(Container, "DataItem.PositionID") %>'>
> > </asp:Label>
> > </ItemTemplate>
> > <FooterTemplate>
> > <asp:Label id="lblPositionIDFooter" runat="server">
> > </asp:Label>
> > </FooterTemplate>
> > </asp:TemplateColumn>
> > <asp:TemplateColumn >
> > <ItemTemplate>
> > <asp:Label id="lblQuestionUnique" runat="server" Text='<%#
> >DataBinder.Eval(Container, "DataItem.QuestionUnique") %>'>
> > </asp:Label>
> > </ItemTemplate>
> > <FooterTemplate>
> > <asp:Label id="lblQuestionUniqueFooter" runat="server">
> > </asp:Label>
> > </FooterTemplate>
> > </asp:TemplateColumn>
> > <asp:BoundColumn DataField="AnswerUnique" visible="false"

ReadOnly="true"
> >HeaderText="AnswerUnique"></asp:BoundColumn>
> > <asp:EditCommandColumn EditText="<img

src='..\images\Edit.png'border='0'
> >id='textbox1'>" visible="true"
> > ButtonType="LinkButton"
> > UpdateText="<img src='..\images\update.png' border='0'>"
> >CancelText="<img src='..\images\Cancel.png' border='0'>" />
> > <asp:TemplateColumn >
> > <FooterTemplate>
> > <asp:LinkButton CommandName="Insert" Text="<img
> >src='..\images\Add.gif'border='0'>" ID="btnAdd" Runat="server" />
> > </FooterTemplate>
> > <ItemTemplate>
> > <asp:LinkButton CommandName="Delete" Text="<img
> >src='..\images\Delete.gif'border='0'>" ID="btnDel" Runat="server" />
> > </ItemTemplate>
> > </asp:TemplateColumn>
> > </Columns>
> ></asp:DataGrid>
>
>************************************************* **************************

************
> >
> >I have the DataGrid by doing something like:
> >
> > for each oItem as DataListItem in DataList1.Items
> > Dim oGrid as DataGrid =

CType(oItem.FindControl("DataGrid1"),DataGrid)
> >
> >How would I use oGrid to find and set "lblPositionIDFooter" and
> >"lblQuestionUniqueFooter"?
> >
> >I need this as I need a place to put the PositionID and QuestionUnique
> >as
> >they are keys I need to use in my Insert statement. I am inserting
> >rows
> >from the Footer and need to get these variables from some where, so
> >this
> >seems to be the most logical place to store them.
> >
> >Thanks,
> >
> >Tom.
> >
>


Nov 18 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.