Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Problem with DataGrid inside a DataList

Reply
Thread Tools

Problem with DataGrid inside a DataList

 
 
Mikkel Olsen
Guest
Posts: n/a
 
      03-06-2004
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") %>
<aspataGrid 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>
</aspataGrid>
</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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CheckBox Outside DataList & Labels Inside DataList rn5a@rediffmail.com ASP .Net 1 12-24-2006 02:28 PM
How do you bind a datalist that is inside a bound datalist =?Utf-8?B?QVNQIERldmVsb3Blcg==?= ASP .Net 2 09-26-2006 02:18 AM
setting SelectedIndex of DataList nested inside of DataList? Les Caudle ASP .Net 0 05-02-2006 10:44 PM
Databound inside DataList with another DataList Steve ASP .Net 0 02-01-2005 04:39 PM
Setting up a datalist control - Item_DataBound for a datalist in a datalist Nevyn Twyll ASP .Net 8 09-09-2004 10:13 PM



Advertisments