Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get grid data if I know the row #

Status
Not open for further replies.

SJG0526

Programmer
Joined
Jul 5, 2002
Messages
108
Location
US
I have a checkbox control in my datagrid and I can get a string of all the row #s of the checked rows. What I need to do now is get data from another column in the checked rows. I know this must be possible but can't figure it out.

I have, say, rows 0, 4, and 6 checked in column 6. Now when I click a button, I want to create a string containing the ids of those rows (which are stored in the first column of the grid)

Anyone done this? TIA!
 
Also, I don't have access to the id for the checkbox control so I have to go strictly by column # and row#
 
I solved my problem. Hope this helps someone.[smile2]

I'm using Andy Smith's very excellent free control RowSelectorColumn for the checkbox column.

I assigned the DataKeyField attribute on the datagrid to be the id field I need for each row.

Code:
<asp:datagrid id="grdChoices" runat="server" ... DataKeyField="TID">
.
.
.						
    <Columns>
	<asp:BoundColumn DataField="TID" Visible="False" />
	<mbrsc:RowSelectorColumn SelectionMode="Multiple" AllowSelectAll="true" />
        .
        .
        .
    </Columns>
</asp:datagrid>
In my vb.net code-behind I do this:
Code:
Private Sub btnEdit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnEdit.Click
        Dim rsc As RowSelectorColumn = RowSelectorColumn.FindColumn(Me.grdChoices)
        If rsc.SelectedIndexes.Length.ToString < 1 Then
            '-- nothing checked
            Me.lblError.Text = "Please select at least 1 row."
        Else
            Me.lblError.Text = ""
            '-- compose string of all topic ids that were selected
            Dim sTIDList As String = "~"
            For Each si As Integer In rsc.SelectedIndexes
                '-- DataKeys is a collection of all primary keys for checked rows.  Primary key
                '-- is set on the datagrid as an attribute (datakeyfield=...)
                sTIDList = sTIDList & Me.grdChoices.DataKeys(si) & "~"
            Next
        End If
    End Sub
Now I have a string delimited by ~ that contains all the TID keys I need for my next step.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top