Getting to the footer in Datalist

T

tshad

I need to get to a status label I have on my footer section of my datalist.

There is no event happening that would go to the footer. I am just doing
some processing and want to update the label on the footer.

At the moment, I go through the dataListItems like so:

for each oItem as DataListItem in DataList1.Items
trace.warn("inside for loop oItem type = " &
oItem.itemType.ToString())
Dim oGrid as DataGrid =
CType(oItem.FindControl("DataGrid1"),DataGrid)
thePanel = CType(oItem.FindControl("dataListPanel"),Panel)
....
next

But the footer is not part of the dataListItems. If I have 8 rows,
datalist.items.count shows 8. This is without the footer. So going through
the list doesn't help me as I never see the footer.

Therefore, how do I get access to the Label that is on the footer?

Thanks

Tom
 
T

tshad

Scott Allen said:
Hi Tom,

Headers and footers are in the Controls collection, and not in the
Items colletion (as you've found out).

See "Finding Controls In Headers and Footers" in the following
article:
http://odetocode.com/Articles/116.aspx

The article was pretty good, but I can't seem to make it work.

Here is what I have:

The footer section:
******************************************************************************************
<FooterTemplate>
<SeparatorTemplate>
<hr style="margin:0">
</SeparatorTemplate>
<asp:Button ID="CollapseAll" visible=false text="Collapse All"
runat="server" onClick="collapseAll"/>;
<asp:Button ID="ExpandAll" visible=false text="Expand All"
runat="server" onClick="expandAll"/>;
<asp:Button ID="Submit" text=" Submit " runat="server"
onClick="submitSkillsTest"/>;
<asp:ImageButton ID="UpQuestion" text="Move Up" visible=true
runat="server" ImageUrl="../images/arrowLeft.gif"
style="height:16px;width:16px;" CommandName="Up"
OnClick="PreviousPage_Click" AlternateText="^"/>&nbsp;&nbsp;
<asp:ImageButton ID="DownQuestion" text="Move Down"
visible=true runat="server" ImageUrl="../images/arrowRight.gif"
style="height:16px;width:16px;" CommandName="Down" OnClick="NextPage_Click"
AlternateText="v"/>
<asp:Label ID="AnswerStatus" runat="server"/>
</FooterTemplate>
</asp:datalist>
********************************************************************************************

The code to find "AnswerStatus":

********************************************************************************************
Dim footerIndex as integer = DataList1.Controls(0).Controls.Count-1
trace.warn("footerIndex = " & footerIndex)
Dim AnswerStatus as Label =
CType(DataList1.Controls(0).Controls(footerIndex).FindControl("AnswerStatus"),Label)

if not AnswerStatus is nothing then
trace.warn("found the status label in the footer")
end if
********************************************************************************************

Part of the trace showing the above messages:
******************************************************************************************
inside Expandall 0.021046 0.014236
footerIndex = 2 0.021091 0.000044
inside for loop oItem type = Item 0.021137 0.000047
******************************************************************************************
As you can see the 2nd trace.warn is not showing.

Another part of the trace showing the footer:
**************************************************************
DataList1:_ctl8
System.Web.UI.WebControls.DataListItem 780 0
DataList1:_ctl8:_ctl0 System.Web.UI.LiteralControl 101 0
DataList1:_ctl8: CollapseAll
System.Web.UI.WebControls.Button 0 0
DataList1:_ctl8:_ctl1 System.Web.UI.LiteralControl 22 0
DataList1:_ctl8:ExpandAll System.Web.UI.WebControls.Button 0 0
DataList1:_ctl8:_ctl2 System.Web.UI.LiteralControl 22 0
DataList1:_ctl8:Submit System.Web.UI.WebControls.Button 142
0
DataList1:_ctl8:_ctl3 System.Web.UI.LiteralControl 22 0
DataList1:_ctl8:UpQuestion System.Web.UI.WebControls.ImageButton
184 0
DataList1:_ctl8:_ctl4 System.Web.UI.LiteralControl 30 0
DataList1:_ctl8:DownQuestion System.Web.UI.WebControls.ImageButton 191
0
DataList1:_ctl8:_ctl5 System.Web.UI.LiteralControl 10 0
DataList1:_ctl8:AnswerStatus System.Web.UI.WebControls.Label 47 0
DataList1:_ctl8:_ctl6 System.Web.UI.LiteralControl 9 0
_ctl8
System.Web.UI.LiteralControl 8 0
***************************************************************
As you can see "AnswerStatus" is there.

What am I missing?

Also, why would the FooterIndex be 2?

Thanks,

Tom
 
T

tshad

Also, here is part of the viewsource where the footer is:

************************************************************************************
</tr><tr>
<td align="Center">
<SeparatorTemplate>

<hr style="margin:0">
</SeparatorTemplate>
&nbsp;&nbsp;
&nbsp;&nbsp;
<input type="submit" name="DataList1:_ctl8:Submit" value=" Submit
" id="DataList1__ctl8_Submit" AlternateText="Click here to see details"
/>&nbsp;&nbsp;
<input type="image" name="DataList1:_ctl8:UpQuestion"
id="DataList1__ctl8_UpQuestion" text="Move Up" src="../images/arrowLeft.gif"
alt="^" border="0" style="height:16px;width:16px;" />&nbsp;&nbsp;
<input type="image" name="DataList1:_ctl8:DownQuestion"
id="DataList1__ctl8_DownQuestion" text="Move Down"
src="../images/arrowRight.gif" alt="v" border="0"
style="height:16px;width:16px;" />
<span id="DataList1__ctl8_AnswerStatus"></span>
</td>

</tr>
</table>
*********************************************************************************

Thanks,

Tom
 
T

tshad

Me again.

Figured it out.

The dataGrid must have one more level of controls that the DataList. I put
a small set of code in my program to track the Controls (after seeing how
yours worked).

************************************************************************************
dim ktr1 as integer
dim ktr2 as integer
trace.warn("number of controls at top = " & DataList1.Controls.Count)
for ktr1 = 0 to DataList1.Controls.Count - 1
trace.warn("Control " & ktr1 & " = " &
DataList1.Controls(ktr1).getType().ToString() & " count = " &
DataList1.Controls(ktr1).controls.count)
for ktr2 = 0 to DataList1.Controls(ktr1).controls.count-1
trace.warn(" Control " & ktr2 & " = " &
DataList1.Controls(ktr1).Controls(ktr2).getType().ToString() & " count = " &
DataList1.Controls(ktr1).Controls(ktr2).controls.count)
next
next

Dim footerIndex as integer = DataList1.Controls.Count-1
trace.warn("footerIndex = " & footerIndex)
Dim AnswerStatus as Label =
CType(DataList1.Controls(footerIndex).FindControl("AnswerStatus"),Label)
*********************************************************************************

I got the following results in my trace:
*******************************************************************************
number of controls at top = 9
Control 0 = System.Web.UI.WebControls.DataListItem count = 3
Control 0 = System.Web.UI.LiteralControl count = 0
Control 1 = System.Web.UI.WebControls.Panel count = 13
Control 2 = System.Web.UI.LiteralControl count = 0
Control 1 = System.Web.UI.WebControls.DataListItem count = 3
Control 0 = System.Web.UI.LiteralControl count = 0
Control 1 = System.Web.UI.WebControls.Panel count = 13
Control 2 = System.Web.UI.LiteralControl count = 0
Control 2 = System.Web.UI.WebControls.DataListItem count = 3
Control 0 = System.Web.UI.LiteralControl count = 0
Control 1 = System.Web.UI.WebControls.Panel count = 13
Control 2 = System.Web.UI.LiteralControl count = 0
Control 3 = System.Web.UI.WebControls.DataListItem count = 3
Control 0 = System.Web.UI.LiteralControl count = 0
Control 1 = System.Web.UI.WebControls.Panel count = 13
Control 2 = System.Web.UI.LiteralControl count = 0
Control 4 = System.Web.UI.WebControls.DataListItem count = 3
Control 0 = System.Web.UI.LiteralControl count = 0
Control 1 = System.Web.UI.WebControls.Panel count = 13
Control 2 = System.Web.UI.LiteralControl count = 0
Control 5 = System.Web.UI.WebControls.DataListItem count = 3
Control 0 = System.Web.UI.LiteralControl count = 0
Control 1 = System.Web.UI.WebControls.Panel count = 13
Control 2 = System.Web.UI.LiteralControl count = 0
Control 6 = System.Web.UI.WebControls.DataListItem count = 3
Control 0 = System.Web.UI.LiteralControl count = 0
Control 1 = System.Web.UI.WebControls.Panel count = 13
Control 2 = System.Web.UI.LiteralControl count = 0
Control 7 = System.Web.UI.WebControls.DataListItem count = 3
Control 0 = System.Web.UI.LiteralControl count = 0
Control 1 = System.Web.UI.WebControls.Panel count = 13
Control 2 = System.Web.UI.LiteralControl count = 0
Control 8 = System.Web.UI.WebControls.DataListItem count = 13
Control 0 = System.Web.UI.LiteralControl count = 0
Control 1 = System.Web.UI.WebControls.Button count = 0
Control 2 = System.Web.UI.LiteralControl count = 0
Control 3 = System.Web.UI.WebControls.Button count = 0
Control 4 = System.Web.UI.LiteralControl count = 0
Control 5 = System.Web.UI.WebControls.Button count = 0
Control 6 = System.Web.UI.LiteralControl count = 0
Control 7 = System.Web.UI.WebControls.ImageButton count = 0
Control 8 = System.Web.UI.LiteralControl count = 0
Control 9 = System.Web.UI.WebControls.ImageButton count = 0
Control 10 = System.Web.UI.LiteralControl count = 0
Control 11 = System.Web.UI.WebControls.Label count = 0
Control 12 = System.Web.UI.LiteralControl count = 0

footerIndex = 8
found the status label in the footer
*********************************************************************************There is the "AnswerStatus" label 2nd to last in the list. An you can seethat the Find control is working fine now.I am curious about the LiteralControl that shows up after each control.Thanks,Tom"tshad" <[email protected]> wrote in messageAlso, here is part of the viewsource where the footer is:>>************************************************************************************> </tr><tr>> <td align="Center">> <SeparatorTemplate>>> <hr style="margin:0">> </SeparatorTemplate>> &nbsp;&nbsp;> &nbsp;&nbsp;> <input type="submit" name="DataList1:_ctl8:Submit" value=" Submit" id="DataList1__ctl8_Submit" AlternateText="Click here to see details"/>&nbsp;&nbsp;> <input type="image" name="DataList1:_ctl8:UpQuestion"id="DataList1__ctl8_UpQuestion" text="Move Up" src="../images/arrowLeft.gif"alt="^" border="0" style="height:16px;width:16px;" />&nbsp;&nbsp;> <input type="image" name="DataList1:_ctl8:DownQuestion"id="DataList1__ctl8_DownQuestion" text="Move Down"src="../images/arrowRight.gif" alt="v" border="0"style="height:16px;width:16px;" />> <span id="DataList1__ctl8_AnswerStatus"></span>> </td>>> </tr>> </table>>*********************************************************************************>> Thanks,>> Tom> "tshad" <[email protected]> wrote in message"Scott Allen" <[email protected]> wrote in messageHi Tom,>>>>>> Headers and footers are in the Controls collection, and not in the>>> Items colletion (as you've found out).>>>>>> See "Finding Controls In Headers and Footers" in the following>>> article:>>> http://odetocode.com/Articles/116.aspx>>>> The article was pretty good, but I can't seem to make it work.>>>> Here is what I have:>>>> The footer section:>>******************************************************************************************>> <FooterTemplate>>> <SeparatorTemplate>>> <hr style="margin:0">>> </SeparatorTemplate>>> <asp:Button ID="CollapseAll" visible=false text="Collapse All"runat="server" onClick="collapseAll"/>;>> <asp:Button ID="ExpandAll" visible=false text="Expand All"runat="server" onClick="expandAll"/>;>> <asp:Button ID="Submit" text=" Submit " runat="server"onClick="submitSkillsTest"/>;>> <asp:ImageButton ID="UpQuestion" text="Move Up" visible=truerunat="server" ImageUrl="../images/arrowLeft.gif"style="height:16px;width:16px;" CommandName="Up"OnClick="PreviousPage_Click" AlternateText="^"/>&nbsp;&nbsp;>> <asp:ImageButton ID="DownQuestion" text="Move Down"visible=true runat="server" ImageUrl="../images/arrowRight.gif"style="height:16px;width:16px;" CommandName="Down" OnClick="NextPage_Click"AlternateText="v"/>>> <asp:Label ID="AnswerStatus" runat="server"/>>> </FooterTemplate>>> </asp:datalist>>>********************************************************************************************>>>> The code to find "AnswerStatus":>>>>********************************************************************************************>> Dim footerIndex as integer = DataList1.Controls(0).Controls.Count-1>> trace.warn("footerIndex = " & footerIndex)>> Dim AnswerStatus as Label =CType(DataList1.Controls(0).Controls(footerIndex).FindControl("AnswerStatus"),Label)>>>> if not AnswerStatus is nothing then>> trace.warn("found the status label in the footer")>> end if>>********************************************************************************************>>>> Part of the trace showing the above messages:>>******************************************************************************************>> inside Expandall 0.021046 0.014236>> footerIndex = 2 0.021091 0.000044>> inside for loop oItem type = Item 0.021137 0.000047>>******************************************************************************************>> As you can see the 2nd trace.warn is not showing.>>>> Another part of the trace showing the footer:>> **************************************************************>> DataList1:_ctl8 System.Web.UI.WebControls.DataListItem 780 0>> DataList1:_ctl8:_ctl0 System.Web.UI.LiteralControl 1010>> DataList1:_ctl8: CollapseAllSystem.Web.UI.WebControls.Button 0 0>> DataList1:_ctl8:_ctl1 System.Web.UI.LiteralControl 220>> DataList1:_ctl8:ExpandAll System.Web.UI.WebControls.Button 0 0>> DataList1:_ctl8:_ctl2 System.Web.UI.LiteralControl 220>> DataList1:_ctl8:Submit System.Web.UI.WebControls.Button142 0>> DataList1:_ctl8:_ctl3 System.Web.UI.LiteralControl 220>> DataList1:_ctl8:UpQuestion System.Web.UI.WebControls.ImageButton184 0>> DataList1:_ctl8:_ctl4 System.Web.UI.LiteralControl 300>> DataList1:_ctl8:DownQuestion System.Web.UI.WebControls.ImageButton191 0>> DataList1:_ctl8:_ctl5 System.Web.UI.LiteralControl 100>> DataList1:_ctl8:AnswerStatus System.Web.UI.WebControls.Label 47 0>> DataList1:_ctl8:_ctl6 System.Web.UI.LiteralControl 90>> _ctl8 System.Web.UI.LiteralControl 8 0>> ***************************************************************>> As you can see "AnswerStatus" is there.>>>> What am I missing?>>>> Also, why would the FooterIndex be 2?>>>> Thanks,>>>> Tom>>>>>>>> -->>> Scott>>> http://www.OdeToCode.com/blogs/scott/>>>>>> On Thu, 10 Mar 2005 11:11:47 -0800, "tshad">>> <[email protected]> wrote:>>>>>>>I need to get to a status label I have on my footer section of mydatalist.>>>>>>>>There is no event happening that would go to the footer. I am justdoing>>>>some processing and want to update the label on the footer.>>>>>>>>At the moment, I go through the dataListItems like so:>>>>>>>> for each oItem as DataListItem in DataList1.Items>>>> trace.warn("inside for loop oItem type = " &>>>>oItem.itemType.ToString())>>>> Dim oGrid as DataGrid =>>>>CType(oItem.FindControl("DataGrid1"),DataGrid)>>>> thePanel = CType(oItem.FindControl("dataListPanel"),Panel)>>>>...>>>> next>>>>>>>>But the footer is not part of the dataListItems. If I have 8 rows,>>>>datalist.items.count shows 8. This is without the footer. So goingthrough>>>>the list doesn't help me as I never see the footer.>>>>>>>>Therefore, how do I get access to the Label that is on the footer?>>>>>>>>Thanks>>>>>>>>Tom>>>>>>>>>>>>>
 
T

tshad

Scott Allen said:
Cool, glad you got it working!

Yes, it made a few things a little more clear, also.

Here is what I found out in my tests that might help someone else out.

Doing this I found that the DataGrid has one more set of controls than the
Datalist.



The dataGrid must have one more level of controls that the DataList. I put
a small set of code in my program to track the Controls (after seeing how
yours worked).



To get a control in a DataList Footer you would do the following:



Dim footerIndex as integer = DataList1.Controls.Count-1
Dim AnswerStatus as
Label=CType(DataList1.Controls(footerIndex).FindControl("AnswerStatus"),Label)



You could shorten it to:
CType(DataList1.Controls(DataList1.Controls.Count-1).FindControl("AnswerStatus"),Label)



To find it in the DataGrid (which has another level of controls) you would
do:

CType(DataGrid1.Control(0).Controls(DataList1.Controls.Count-1).FindControl("AnswerStatus"),Label)



To get a control in a DataList Header you would do the following:


CType(DataList1.Controls(0).FindControl("AnswerStatus"),Label)



To find it in the DataGrid (which has another level of controls) you would
do:

CType(DataGrid1.Control(0).Controls(0).FindControl("AnswerStatus"),Label)



I just don't know what the literal control that shows up after each control
is for, but it is important to know if you are looking throught the
controls. The Literal controls are always after the web controls (at least
there were in the traces I looked at) so your web controls are every other
control.



Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top