For what it's worth I've found the same problem with datagrids inside a
datagrid.
I resolved it by programmatically adding the event to the grid each time the
grid was created.
A
[quoted text, click to view] "Mikkel Olsen" <olsenmikkel@hotmail.com> wrote in message
news:OvLKsXJBEHA.3184@TK2MSFTNGP09.phx.gbl...
> Hi.
>
> I have a problem regarding to the DataGrid_ItemDataBound event. I cant run
> this event when my datagrid is inside a DataList.
>
> The ItemDataBound for DataList1 is working well, but it never raises the
> DataGrid1_ItemDataBound event.
>
> Thx.
>
> Mikkel, Denmark
>
>
> My aspx-code:
>
> <asp:datalist id="DataList1" runat="server" Width="800px"
RepeatColumns="1"
> RepeatDirection="Horizontal" CellPadding="4" CellSpacing="4">
> <ItemStyle Font-Size="X-Small" Font-Names="Tahoma"></ItemStyle>
> <ItemTemplate>
> <%# Container.DataItem("HostName") %>
> <asp:DataGrid id="DataGrid1" runat="server"
CellPadding="3"
> BorderColor="#999999" BorderStyle="None" BorderWidth="0px"
> BackColor="White" GridLines="Vertical"
> AutoGenerateColumns="False" ShowHeader="False">
> <ItemStyle Font-Size="X-Small"
> ForeColor="Black"></ItemStyle>
> <Columns>
> <asp:BoundColumn
> DataField="Description"></asp:BoundColumn>
> </Columns>
> </asp:DataGrid>
> </ItemTemplate>
> </asp:datalist>
>
>
> My aspx.vb-code:
>
> Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
> GetHosts()
> End Sub
>
> Public Function GetHosts()
> Dim SqlStr As String
> SqlStr = "Select HOSTS.Hostid, Hostname from HOSTS"
> Dim MyCommand = New SqlDataAdapter(SqlStr, myConnection)
> Dim DS4 As New DataSet
> MyCommand.Fill(DS4, "HOSTS")
> DataList1.DataSource = DS4.Tables("HOSTS").DefaultView
> DataList1.DataBind()
> End Function
>
> Private Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.DataListItemEventArgs) Handles
> DataList1.ItemDataBound
> If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
> ListItemType.AlternatingItem Then
> Dim drv As DataRowView = e.Item.DataItem
> Dim HostID As String = drv.Row.ItemArray(0)
> Dim childgrid As DataGrid
> Dim Ds3 As DataSet = GetServices(HostID)
> childgrid = e.Item.FindControl("DataGrid1")
> childgrid.Visible = True
> childgrid.DataSource = Ds3
> childgrid.DataBind()
> End If
> End Sub
>
> Public Function GetServices(ByVal hostid As String) As DataSet
> Dim SqlStr As String
> SqlStr = "GetService"
> Dim MyCommand2 = New SqlDataAdapter(SqlStr, myConnection2)
> MyCommand2.SelectCommand.CommandType = CommandType.StoredProcedure
> MyCommand2.SelectCommand.Parameters.Add(New SqlParameter("@hostid",
> SqlDbType.Int))
> MyCommand2.SelectCommand.Parameters("@hostid").Value = hostid
> Dim DS2 As New DataSet
> MyCommand2.Fill(DS2, "Services")
> Return DS2
> End Function
> Private Sub DataList1_ItemDataBound(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.DataListItemEventArgs) Handles
> DataList1.ItemDataBound
> if e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
> ListItemType.AlternatingItem Then
> Dim drv As DataRowView = e.Item.DataItem
> Dim HostID As String = drv.Row.ItemArray(0)
> Dim childgrid As DataGrid
> Dim Ds3 As DataSet = GetServices(HostID)
> childgrid = e.Item.FindControl("DataGrid1")
> childgrid.Visible = True
> childgrid.DataSource = Ds3
> childgrid.DataBind()
> End If
> End Sub
>
>
>