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

can't find control in datalist

P: n/a
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="spMSSASPGetOutstandingConditionsInInve storRevi
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.........
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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.......
-----Original Message-----
I have a datagrid control within a datalist control. WhenI try and do a "Find" on the control, the object comes
back with nothing and then my pgm crashes. I am 100% surethat 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 datagridtemplatecolumns, 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="spMSSASPGetOutstandingConditionsInInv estorRev iewStep" 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.........
.

Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.