locked
gridview with data and non data RRS feed

  • Question

  • User1806930132 posted

    I have 2 radiobuttons, gridview

    on clicking yes radio button gridview displays....grid view has add,edit,delete.

    if user cliks no...no gridview displayed

    now I want an if startment which says if GridView1 has data..then radiobuttonno.visible=false

    else radiobutton.visible=true

    how do I write this in pageload?

    Friday, May 13, 2016 11:59 AM

Answers

  • User-271186128 posted

    Hi msaahil2015,

    From my point of view, I suggest you can use GridView DataBound event. you can refer to the following code:

        Protected Sub GridView1_DataBound(sender As Object, e As EventArgs)
            If GridView1.Rows.Count = 0 Then
                radiobutton.Visible = False
    
            Else
                radiobutton.Visible = True
            End If
        End Sub

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, May 14, 2016 3:22 AM

All replies

  • User475983607 posted

    Well, if the gridview's data source has records then set radio button visibility.  

    It would help if you posted the relevant source code rather than making us guess.

    Friday, May 13, 2016 12:08 PM
  • User1806930132 posted

    Protected Sub SqlDataSourceab_Deleting(sender As Object, e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSourceab.Deleting
            Radiobutton2.Visible = True
        End Sub

    On this page I have Gridview1

    On delete command I want to check if there are any rows in the gridview, if yes then radiobutton2.visible=false

    else if no rows in the gridview to delete then radiobutton1.visible=true

    Friday, May 13, 2016 11:03 PM
  • User-271186128 posted

    Hi msaahil2015,

    From my point of view, I suggest you can use GridView DataBound event. you can refer to the following code:

        Protected Sub GridView1_DataBound(sender As Object, e As EventArgs)
            If GridView1.Rows.Count = 0 Then
                radiobutton.Visible = False
    
            Else
                radiobutton.Visible = True
            End If
        End Sub

    Best regards,
    Dillion

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, May 14, 2016 3:22 AM