• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

BulletedList: Returning values from dynamic list


I have a gridview which I have a databound bulletedlist as one of the columns.  I can't seem to get the VALUE of the selected item.  I get the following error that I have attached.
(bl in the example is nothing.  dg is populated with the grid)
Any assistance would be great.  I've gone round and round with this and needed another set(s) of eyes.
Thanks in advance!

Protected Sub BulletedListContent_Click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.BulletedListEventArgs)
        Dim dg As GridView = CType(Me.LoginView1.FindControl("GrdStudents"), GridView)
        Dim bl As BulletedList = CType(dg.FindControl("blcontent"), BulletedList)
        Dim position As Integer = e.Index
        Dim txtcontent As String
        'Dim li As ListItem = blContent.Items(position)
        txtcontent = bl.Items(e.Index).Text
    End Sub
<asp:GridView ID="GrdStudents" runat="server" AutoGenerateColumns="False" DataKeyNames="StudentId,SchYear"
DataSourceID="SqlStudSchool" AllowPaging="True" AllowSorting="True" HeaderStyle-CssClass="datagrid"
CellPadding="4" ForeColor="#333333" GridLines="None" OnRowDataBound="GrdStudents_RowDataBound"
EmptyDataText="No Students to Display">
<asp:TemplateField HeaderText="Content Area">
<asp:BulletedList ID="blContent" runat="server" DataTextField="Content" DataValueField="Content" DisplayMode="LinkButton" OnClick="GrdStudents_bl">
<ItemStyle HorizontalAlign="Left" Width="150px" />

Open in new window

1 Solution
Your line 3 will not find the control as the control is inside an item template that is why it shows the null reference error. has to be something like this
Dim bl As BulletedList = CType(dg.Rows[0].Cells[<cellnumber>].FindControl("blcontent"), BulletedList)

Open in new window

wayneburrAuthor Commented:
Very Nice!
A billion points to you!

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now