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

BulletedList: Returning values from dynamic list

VS2008
ASP.NET3.6
VB

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">
<Columns>
.......
.......
<asp:TemplateField HeaderText="Content Area">
<ItemTemplate>
<asp:BulletedList ID="blContent" runat="server" DataTextField="Content" DataValueField="Content" DisplayMode="LinkButton" OnClick="GrdStudents_bl">
</asp:BulletedList>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="150px" />
</asp:TemplateField>
......

Open in new window

bulletedlist2-error.jpg
0
wayneburr
Asked:
wayneburr
1 Solution
 
sunithnairCommented:
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

0
 
wayneburrAuthor Commented:
Very Nice!
A billion points to you!
Thanks.
0

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