can't find control in datalist

B

bill yeager

I have a datagrid control within a datalist control. When
I try and do a "Find" on the control, the object comes
back with nothing and then my pgm crashes. I am 100% sure
that my datagird inside my datalist has an id
of "Datagrid3". dgChild comes back with "Nothing" while
debugging.

Here is my code in the itemdatabound event for the
datalist:
<code>
Private Sub DataList1_ItemDataBound(ByVal sender As
System.Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
DataList2.ItemDataBound

'For each parent record on the datalist, select
the child records that it belongs to
If (e.Item.ItemType = ListItemType.Item) OrElse
(e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim dgChild As DataGrid = DirectCast
(FindControl("DataGrid3"), DataGrid)
dgChild.DataSource = DirectCast
(e.Item.DataItem, DataRowView).CreateChildView
(relBulkConds)
End If

End Sub
</code>

I've been able to find controls before on a datagrid
before, but I havn't tried yet to actually find a
DATAGRID control within a datalist. I know I needed to
make the fields that I am going to access in the datagrid
templatecolumns, but how can I find the DATAGRID control
within my datalist?

Here is my HTML:
<code>
<ItemTemplate>
<asp:label id=Name2 runat="server" Text='<%#
DataBinder.Eval(Container, "DataItem.Name")%>'>
</asp:label>
<asp:RadioButtonList id="Radiobuttonlist2" runat="server"
AutoPostBack="True" RepeatDirection="Horizontal">

<asp:ListItem Value="1">Waive All
Cond</asp:ListItem>

<asp:ListItem Value="0">Don't Waive Any
Conditions</asp:ListItem>

</asp:RadioButtonList>
<asp:DataGrid id=Datagrid3 runat="server"
AutoGenerateColumns="False"
DataMember="spMSSASPGetOutstandingConditionsInInvestorRevi
ewStep" DataKeyField="Lock_Number" DataSource="<%#
DsOutstandingCondsInInvestorRvw1 %>" BackColor="White"
BorderColor="#999999" BorderStyle="None"
BorderWidth="1px" CellPadding="3" GridLines="Vertical">

<SelectedItemStyle Font-Bold="True"
ForeColor="White" BackColor="#008A8C"></SelectedItemStyle>

<AlternatingItemStyle
BackColor="Gainsboro"></AlternatingItemStyle>

<ItemStyle ForeColor="Black"
BackColor="#EEEEEE"></ItemStyle>

<HeaderStyle Font-Bold="True" ForeColor="White"
BackColor="#000084"></HeaderStyle>

<FooterStyle ForeColor="Black"
BackColor="#CCCCCC"></FooterStyle>
<Columns>

<asp:TemplateColumn>

<ItemTemplate>

<asp:checkbox runat="server"
id="Condition3"></asp:checkbox>

</ItemTemplate>

</asp:TemplateColumn>

<asp:BoundColumn DataField="Name" ReadOnly="True"
HeaderText="Name"></asp:BoundColumn>

<asp:TemplateColumn>

<ItemTemplate>

<asp:label runat="server" id="LoanID3"
Text='<%# DataBinder.Eval(Container, "DataItem.LoanID") %

</asp:label>

</ItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn>

<ItemTemplate>

<asp:label runat="server"
id="LockNumber3" Text='<%# DataBinder.Eval
(Container, "DataItem.Lock_Number") %>'>

</asp:label>

</ItemTemplate>

</asp:TemplateColumn>

<asp:TemplateColumn>

<ItemTemplate>

<asp:label runat="server"
id="ConditionDetailID3" Text='<%# DataBinder.Eval
(Container, "DataItem.ConditionDetailID") %>'>

</asp:label>

</ItemTemplate>

</asp:TemplateColumn>

<asp:BoundColumn DataField="ConditionID"
ReadOnly="True"
HeaderText="ConditionID"></asp:BoundColumn>

<asp:BoundColumn DataField="Description"
ReadOnly="True"
HeaderText="Description"></asp:BoundColumn>

<asp:BoundColumn DataField="Comment"
ReadOnly="True" HeaderText="Comment"></asp:BoundColumn>
</Columns>

<PagerStyle HorizontalAlign="Center"
ForeColor="Black" BackColor="#999999"
Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
</ItemTemplate>

Thanks so much for your help.........
 
B

bill yeager

I figured out how to find the control properly:
<code>
Dim dgChild As DataGrid = e.Item.FindControl("DataGrid3")
</code>

However, during a postback to one of the radio buttons
inside the datalist, I set up and event as follows:
<code>
Protected WithEvents RadioButtonList2 As RadioButtonList
..
..
..
Public Sub rblRadioButtonList2_SelectedIndexChanged(ByVal
sender As Object, ByVal e As System.EventArgs) Handles
RadioButtonList2.SelectedIndexChanged

'Capture the postback event from the
radiobuttonlist
Dim rblConditions As RadioButtonList = DirectCast
(FindControl("RadioButtonList2"), RadioButtonList)
Dim dgChild As DataGrid = DirectCast(FindControl
("DataGrid3"), DataGrid)
Dim chkCondition As CheckBox = DirectCast
(FindControl("Condition3"), CheckBox)
Dim lblLockNumber As Label = DirectCast
(FindControl("LockNumber3"), Label)
Dim lblConditionDetailID As Label = DirectCast
(FindControl("ConditionDetailID3"), Label)
Dim lblLoanID As Label = DirectCast(FindControl
("LoanID3"), Label)
..
..
..
</code>

As it turns out, I can't seem to find any of the controls
like I'm trying above while debugging. The objects all
come back with NOTHING. Why not???

I'm really stumped if someone could please help me.......
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top