Missing one last piece of code: datalist within gridview

After learning about datalists and getting help here, I've almost got this.

here is a working page here of my  gridview:  http://www.theravive.com/workshops/test.aspx

In the fourth column is a datalist.  The datalist is supposed to show Title, Address, Startdate for each record ID.  As you can see, the datalist is not showing up.  I know I'm farily close, and just need a hand with the code.  Here is my ASPX code:

<asp:GridView ID="Gridview1" runat="server" AutoGenerateColumns="False" Height="240px"
            Style="z-index: 100; left: 208px; position: absolute; top: 152px" Width="752px">
            <Columns>
                <asp:BoundField DataField="imagename" />
                <asp:BoundField DataField="RecordID" HeaderText="RecordID">
                    <ItemStyle Width="20px" />
                </asp:BoundField>
                <asp:BoundField DataField="UserID" HeaderText="UserID">
                    <ItemStyle Width="20px" />
                </asp:BoundField>
                <asp:TemplateField>
                    <ItemTemplate>
                         <asp:DataList ID="DataList2" runat="server" Style="z-index: 101; left: 0px; position: absolute;top: 0px">
                            <ItemTemplate>
                             <%# Container.DataItem("Title") %>
                             <%# Container.DataItem("Address") %>
                             <%# Container.DataItem("StartDate") %>
                             </ItemTemplate>
                            </asp:DataList>
                    </ItemTemplate>
                    <ItemStyle Width="500px" />
                </asp:TemplateField>
            </Columns>
        </asp:GridView>

And my entire page of VB code behind is attached.
I know Im supposed to do something in the databound event of the gridview to initiate the datalist, but I'm not sure what.  Can someone help me with the VB codebehind and aspx?
Partial Class test
    Inherits System.Web.UI.Page
    Private MSSQLConnection As New Data.SqlClient.SqlConnection 
    Private MSSQLCommand As Data.SqlClient.SqlCommand
    Private dt As New Data.DataSet
 
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        MSSQLConnection.ConnectionString = "<snipped>"
        fillgridview()
    End Sub
 
    Protected Sub FillGridview()
        dt.Clear()
        Dim result As Integer = 0
        Dim Filename = "", Filesize = "", RecordID = ""
        MSSQLCommand = New Data.SqlClient.SqlCommand _
        ("select ImageName, RecordID, UserID from dbo.workshops", MSSQLConnection)
        Try
            MSSQLConnection.Open()
            Dim DR As New Data.SqlClient.SqlDataAdapter(MSSQLCommand)
            DR.Fill(dt)
            Gridview1.DataSource = dt.Tables(0)
            Gridview1.DataBind()
            MSSQLConnection.Close()
        Catch
        End Try
    End Sub
 
 
 
Protected Sub Gridview1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Gridview1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim data As DataList = e.Row.FindControl("Datalist2")
 
            Dim name As String = e.Row.Cells(0).Text
            If Not name = "Default" Then
                e.Row.Cells(0).Text = "<p align=""right""><img src=""http://www.theravive.com/uploads/images/" & e.Row.Cells(2).Text & "_" & name & """ alt=""pic"" /></p>"
            Else
                e.Row.Cells(0).Text = "<img src=""http://www.theravive.com/uploads/images/deathvalley.jpg"" alt=""pic"" />"
            End If
        End If
    End Sub
End Class

Open in new window

arthurh88Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bele04Commented:
Correct me if I'm wrong but I can't seem to find the part where you're setting the Datasource for your Datalist.  Maybe you're missing that piece of code.
0
arthurh88Author Commented:
yes you are right...where do I set that?  Should I set that in the Databound area of the gridview?  I want my code to be as efficient as possible.  
0
bele04Commented:
Yes, you should set it in the Databound event of your GridView if you have different set of data for each row.  Otherwise if you have only one set of data for all the datalist in the GridView then you can just set it in the designer or after you set the datasource for your GridView.  
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

arthurh88Author Commented:
Hi Bele.  Here is my new databound event for the gridview:

if you look at the page now:  www.theravive.com/test.aspx
the data looks like its there, but not showing up in the proper areas.  

Also, is the code I'm using proper?  As in opening and closing my connection for each item?

    Protected Sub Gridview1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles Gridview1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim data As DataList = e.Row.FindControl("Datalist2")
            MSSQLCommand = New Data.SqlClient.SqlCommand _
                    ("select Title, Address, Startdate from dbo.workshops where userid = '" & e.Row.Cells(2).Text & "'", MSSQLConnection)
            MSSQLConnection.Open()
            data.DataSource = MSSQLCommand.ExecuteReader
            data.DataBind()
            MSSQLConnection.Close()
            Dim name As String = e.Row.Cells(0).Text
            If Not name = "Default" Then
                e.Row.Cells(0).Text = "<p align=""right""><img src=""http://www.theravive.com/uploads/images/" & e.Row.Cells(2).Text & "_" & name & """ alt=""pic"" /></p>"
            Else
                e.Row.Cells(0).Text = "<img src=""http://www.theravive.com/uploads/images/deathvalley.jpg"" alt=""pic"" />"
            End If
 
        End If
    End Sub

Open in new window

0
bele04Commented:
Can't seem to get to that page.  I get a resource cannot be found. But your code looks ok to me.
0
arthurh88Author Commented:
0
arthurh88Author Commented:
THanks a lot!!
0
arthurh88Author Commented:
doh!  Was the absolute positioning of the datalist.  all working now, thanks a lot!!
0
bele04Commented:
remove the absolute positioning of your datalist since that causes all datalist to be located in the same place.
<asp:TemplateField>
                    <ItemTemplate>
                         <asp:DataList ID="DataList2" runat="server">
                            <ItemTemplate>
                             <%# Container.DataItem("Title") %>
                             <%# Container.DataItem("Address") %>
                             <%# Container.DataItem("StartDate") %>
                             </ItemTemplate>
                            </asp:DataList>
                    </ItemTemplate>
                    <ItemStyle Width="500px" />
                </asp:TemplateField>

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.