Please - can anyone share a SelectorField example?

May 14, 2008 at 2:54 AM
I have the selectorField displaying correctly in a GridView - but I'm beating my head against the wall trying to figure out how to retrieve the selected checkboxes in my code-behind. Has anyone seen any documented examples of how to get this working? Can anyone please share a working example of this??

Thanks,

Terry
Dec 9, 2008 at 11:56 PM
try this...


<asp:GridView ID="gvItems" runat="server" AutoGenerateColumns="false" AllowSorting="true" OnSorting="gvItems_OnSorting">
<columns>
    <asp:SelectorField SelectionMode="Multiple" HeaderText="All" />
    <asp:BoundField DataField="pid" HeaderText="ID" SortExpression="pid"  />

'code behind

Dim rsc As SelectorField = gvItems.Columns(0)
 
        If rsc.SelectedIndexes.Length > 0 Then
            Dim gRow As GridViewRow
   
            For Each selectedIndex As Integer In rsc.SelectedIndexes
                gRow = gvItems.Rows(selectedIndex)

                'do whatever with gRow.Cells(1).Text

               
            Next selectedIndex
        End If

Nov 2, 2010 at 11:58 AM
Edited Nov 2, 2010 at 12:21 PM

Has anyone got this working?

The issue I am having is that rsc.SelectedIndexes is always a zero length?

I have stepped through the SelectorField code and all the selectors have a value of Checked = false. Even though I have one to many selected rows.

Is there a step I am missing to get this working?

any help would be much appreciated

thanks in advance

Nov 9, 2010 at 10:19 AM

I manage to get it working doing this:

SelectorField sf = MY_GRIDVIEW.Columns.OfType<SelectorField>().SingleOrDefault();
int[] i = sf.SelectedIndexes;