in
Forums
Blogs
Files
Devexpress.Com
Client Center
Support Center
DevExpress Channel

Select Button in command column

Last post 10/19/2007 5:28 PM by Mehul Harry (Developer Express). 5 replies.
Page 1 of 1 (6 items)
Sort Posts:
Previous Next
  • 9/27/2007 6:17 PM

    Select Button in command column

    This is a very newbie question...I'm trying to create a grid populated with search results. I want the user to be able to use the select button in the command column, have it read the data in that row, and perform a function. I've seen every tutorial that has to do with select, but none of them use the button - they all use checkboxes or custom radio buttons.

     I have the grid set up like this:

    ClientSideEvents-FocusedRowChanged

    ="dxgdSearch_CustomCallback"

    Calls this VB proc:

    Protected Sub dxgdSearch_CustomCallback(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs)

    Session(

    "FocusedRow") = dxgdSearch.GetRowValues(Convert.ToInt32(e.Parameters), New String() {dxgdSearch.KeyFieldName})Dim objLogNum As Object = dxgdSearch.GetSelectedFieldValues("LogNum")

    Dim sLogNum As String = objLogNum.ToString()Dim objCompRefName As Object = dxgdSearch.GetSelectedFieldValues("CompRefName")

    Dim sCompRefName As String = objCompRefName.ToString()Session("LogNum") = sLogNum

    Session(

    "CompRefName") = sCompRefName

    If (Request.QueryString.Get("ReturnURL").Length > 0) ThenResponse.Redirect(Request.QueryString.Get("ReturnURL"))

    End If

    End Sub

    When the page runs, I get an error: dxgdSearch_CustomCallback is undefined.

    Please tell me what I'm doing wrong! Thanks!

    Shelley

  • 9/28/2007 7:47 AM In reply to

    Re: Select Button in command column

    Hi Shelley,

    Yes you can create a select linkbutton and then handle this on the serverside. Try this:

    First "Enable Selection" from the Smart Tag menu. Then bring up the Columns list. Here you can set the properties for the Command Column. Set the ShowSelectCheckBox to false. Then set the SelectButton->Visible to true. You can also set the text, image, etc. for this button. It'll display a link button with the text you specify, if none then it'll say 'Select'. You can the ButtonType property to display a LinkButton, regular button or image.

            <Columns>
                <dxwgv:GridViewCommandColumn VisibleIndex="0">
                    <SelectButton Text="Select Row" Visible="True">
                    </SelectButton>
                </dxwgv:GridViewCommandColumn>
     

    On the serverside you can handle the OnSelectionChanged event and use the GetRowValues for your function. Please take a look at the serverside methods on this demo that reference GetRowValues:

    Enable one row selection in the grid with Radiobuttons

    Thanks.
    Filed under:
  • 10/17/2007 4:20 PM In reply to

    Re: Select Button in command column

    Hi,

    Could you please supply the vb code for the demo identified above (one row selection in the grid with radio buttons)

    Many thanks

    Roy

     

  • 10/19/2007 6:45 AM In reply to

    Re: Select Button in command column

    Hello Roy,

    Here is the VB codebehind:

    Partial Class Grid_Selection_OnRowSelection_OneRowSelectionVB
        Inherits System.Web.UI.Page
     
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
            ClearSelectionOnOtherPages()
        End Sub
        Private Sub ClearSelectionOnOtherPages()
            If grid.Selection.Count <= 1 Then
                Return
            End If
            Dim curPageSelection As Integer = GetSelectedRowOnTheCurrentPage()
            grid.Selection.UnselectAll()
            grid.Selection.SelectRow(curPageSelection)
        End Sub
        Private Function GetSelectedRowOnTheCurrentPage() As Integer
            Dim startIndexOnPage As Integer = grid.PageIndex * grid.SettingsPager.PageSize
            For i As Integer = 0 To grid.VisibleRowCount - 1
                If grid.Selection.IsRowSelected(startIndexOnPage + i) Then
                    Return startIndexOnPage + i
                End If
            Next
            Return -1
        End Function
        Public Overridable Function GetFieldChecked(ByVal item As Object) As String
            If Session("FocusedRow") IsNot Nothing Then
                Dim row As DevExpress.Web.Data.WebDescriptorRowBase = TryCast(item, DevExpress.Web.Data.WebDescriptorRowBase)
                Dim o As Object = grid.GetRowValues(row.VisibleIndex, grid.KeyFieldName)
                Return IIf(Session("FocusedRow").ToString().Trim() = o.ToString().Trim(), "CHECKED", "")
            Else
                Return ""
            End If
        End Function
        Protected Sub grid_CustomCallback(ByVal sender As Object, ByVal e As DevExpress.Web.ASPxGridView.ASPxGridViewCustomCallbackEventArgs)
            Session("FocusedRow") = grid.GetRowValues(Convert.ToInt32(e.Parameters), New String() {grid.KeyFieldName})
        End Sub
    End Class

    Thanks.

  • 10/19/2007 11:35 AM In reply to

    Re: Select Button in command column

    Hi,

    Although I can change selection by choosing radio button on different row, I get an  "Errors on Page" message appear every time I change row.

    I think it must be my column set up in my grid.

    Is it possible to to send me the aspx page that contains the grid in the demo.  (so I can see the settings for the Isselected column and edit template valuesfor the radio button)

    Many thanks,

    Roy

  • 10/19/2007 5:28 PM In reply to

    Re: Select Button in command column

    Hello Roy,

    The ASPX page should be the same but I've created zip that contains both for you. You'll need a copy of the nwind.mdb in your AppData folder. You can find a copy in our Program Files/Developer Express ... folder.

    FocusRowVB.zip

    Thanks.

    Filed under:
Page 1 of 1 (6 items)
Copyright © 1998-2008 Developer Express Inc.
ALL RIGHTS RESERVED