473,396 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Problem with a datagrid inside a datalist

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").Val ue = 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

Nov 18 '05 #1
1 3125
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

"Mikkel Olsen" <ol*********@hotmail.com> wrote in message
news:Ov**************@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").Val ue = 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

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David P. Donahue | last post by:
If I have a DataGrid or DataList on a webpage with an ItemTemplate that includes a button server control, how can I set it in the ItemTemplate so that all the buttons populated in the grid/list...
1
by: Coder Coder | last post by:
Hi I have put a Datagrid inside of a DIV tag to allow scrolling. This works fine, but I would like to store the location of the scrollbar so that when there is a selection (causing a postback), I...
1
by: Bigtoga | last post by:
Okay - I'm going crazy here trying to figure out how to do this - here goes: I have a DataList populated by a DataReader. In the DataReader, a column is present called "IsInCategory". I want to...
1
by: DotNetJunkies User | last post by:
Hi, I was wondering if it is possible to load datagrid into datalist programatically using ITemplate interface with the following structure and place intp placeholder control. PlaceHolder -...
1
by: niv | last post by:
Hi, My dataset consists of a string of data seperated by semicolons. ie 4544512;7878595;9696569;9596586;1235252;5456585;4754565;696 9596
1
by: Raghuram | last post by:
difference between datagrid and datalist
2
by: wolfgang wagner | last post by:
hi all! im trying to implement an m:n relation in a webapplication(here: the realtion between hard and software. there may be many computers with each of them has many installed software). for...
2
by: Alex Smith | last post by:
Hi friends Can anybody tell me where to use datagrid and where to use datalist. Or explain Different between DataGrid and DataList. Regards, Alex
1
by: Charlie | last post by:
Hi: Can the DataGrid or DataList be bound to a strongly typed collection? Thanks, Charlie
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.