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

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

VS2008
ASP.NET3.5
VB

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.
Thanks!
<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>
<ItemTemplate>
<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") %>'>
View</a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="StudentId" HeaderText="StudentId" ReadOnly="True" SortExpression="StudentId">
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="LName" HeaderText="LName" SortExpression="LName">
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="FName" HeaderText="FName" SortExpression="FName">
<ItemStyle Width="100px" />
 </asp:BoundField>
<asp:BoundField DataField="MI" HeaderText="MI" SortExpression="MI">
<ItemStyle Width="15px" />
</asp:BoundField>
<asp:BoundField DataField="BDate" HeaderText="BDate" SortExpression="BDate">
<ItemStyle Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="Grade" HeaderText="Grade" SortExpression="Grade">
<ItemStyle Width="25px" />
</asp:BoundField>
<asp:TemplateField HeaderText="Content Area">
<ItemTemplate>
<asp:BulletedList ID="blContent" runat="server" DataTextField="Content" DataValueField="Content" DisplayMode="LinkButton" OnClick="BulletedListContent_Click">
</asp:BulletedList>
</ItemTemplate>
<ItemStyle HorizontalAlign="Left" Width="150px" />
</asp:TemplateField>
</Columns>
<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" />
</asp:GridView>

Open in new window

BulletedList-Grid.jpg
bulletedlist3-error.jpg
0
wayneburr
Asked:
wayneburr
  • 2
  • 2
1 Solution
 
karakavCommented:
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:

GridView.Rows[bulleted.RowIndex].

hope this helps. I wrote it in C# but I guess you can easily translate it. If you can't just let me know.
0
 
wayneburrAuthor Commented:
If you don't mind, can you resend that syntax for VB?  Thanks!
0
 
karakavCommented:
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

0
 
wayneburrAuthor Commented:
Excellant!
A Zillion points to you is in the mail!
Thanks again!
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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