Problem with DataGrid inside a DataList

Discussion in 'ASP .Net Datagrid Control' started by Mikkel Olsen, Mar 6, 2004.

  1. Mikkel Olsen

    Mikkel Olsen Guest

    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
     
    Mikkel Olsen, Mar 6, 2004
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nevyn Twyll
    Replies:
    8
    Views:
    1,940
  2. Steve
    Replies:
    0
    Views:
    3,078
    Steve
    Feb 1, 2005
  3. Les Caudle
    Replies:
    0
    Views:
    2,028
    Les Caudle
    May 2, 2006
  4. =?Utf-8?B?QVNQIERldmVsb3Blcg==?=

    How do you bind a datalist that is inside a bound datalist

    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=, Sep 25, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    593
    =?Utf-8?B?QVNQIERldmVsb3Blcg==?=
    Sep 26, 2006
  5. Replies:
    1
    Views:
    468
Loading...

Share This Page