Gridview-get selectedrow when selecting a item from a Bulleted List

Posted on 2009-02-19
Last Modified: 2012-05-06

I'm having some difficulty trying to capture which row I am on when I have selected an item from bulletedList (Column from gridview).  I need to capture my row when my event for selecting a item out of the Bulleted list.
Any help would be great.
<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">




<a id="btnShowPopup" runat="server" title='<%# Eval("LName", "Details for {0}") %>'

rel="gb_page[500, 500]" href='<%# Eval("StudentId", "Student_Detail.aspx?ID={0}&TB_iframe=true&height=220&width=500") %>'>




<asp:BoundField DataField="StudentId" HeaderText="StudentId" ReadOnly="True" SortExpression="StudentId">

<ItemStyle Width="100px" />


<asp:BoundField DataField="LName" HeaderText="LName" SortExpression="LName">

<ItemStyle Width="100px" />


<asp:BoundField DataField="FName" HeaderText="FName" SortExpression="FName">

<ItemStyle Width="100px" />


<asp:BoundField DataField="MI" HeaderText="MI" SortExpression="MI">

<ItemStyle Width="15px" />


<asp:BoundField DataField="BDate" HeaderText="BDate" SortExpression="BDate">

<ItemStyle Width="100px" />


<asp:BoundField DataField="Grade" HeaderText="Grade" SortExpression="Grade">

<ItemStyle Width="25px" />


<asp:TemplateField HeaderText="Content Area">


<asp:BulletedList ID="blContent" runat="server" DataTextField="Content" DataValueField="Content" DisplayMode="LinkButton" OnClick="BulletedListContent_Click">



<ItemStyle HorizontalAlign="Left" Width="150px" />



<HeaderStyle CssClass="datagrid" BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />

<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />

<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />

<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />

<EditRowStyle BackColor="#999999" />

<AlternatingRowStyle BackColor="White" ForeColor="#284775" />


Open in new window

Question by:wayneburr
    LVL 4

    Expert Comment

    Instead of using the SelectedRow property of the GridView you can guess it backwards:
    GridViewRow bulleted = (GridViewRow)((BulletedList)sender).NamingContainer;

    The if you want to know the rowIndex your do this:


    hope this helps. I wrote it in C# but I guess you can easily translate it. If you can't just let me know.

    Author Comment

    If you don't mind, can you resend that syntax for VB?  Thanks!
    LVL 4

    Accepted Solution

    Here you go
        Protected Sub BulletedListContent_Click(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.BulletedListEventArgs)
            Dim gridRow As GridViewRow
            Dim bullet As BulletedList
            bullet = CType(sender, BulletedList)
            If Not bullet Is Nothing Then
                gridRow = CType(bullet.NamingContainer, GridViewRow)
                'If you want to access the row via the grid 
                Dim index As Integer
                index = gridRow.RowIndex
            End If
        End Sub

    Open in new window


    Author Closing Comment

    A Zillion points to you is in the mail!
    Thanks again!

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now