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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refreshing Greidviews in .NET

Status
Not open for further replies.

acent

Technical User
Feb 17, 2006
247
0
0
US
Greetings,

I've been struggling with refreshing gridviews for a while now. My good buddy Google hasn't been able to solve this sucker for me. I'm using VB.NET 2.0 with ASP.NET.

I'm binding my gridviews like so:
Code:
  Private Sub get_events
    Dim oleConn as New oleDbConnection(ConfigurationManager.ConnectionStrings("accdb").ConnectionString)
    Dim oleCMD As New OleDbCommand
    oleCMD.Connection = oleConn
    Try
      oleConn.Open
      oleCMD.CommandText = "EXECUTE view_flaggedactgevents"
      gvEvents.DataSource = oleCMD.ExecuteReader
      gvEvents.DataBind
      gvEvents.DataSource.Close
    Catch ex As Exception
      lblError.Text = ex.Message
    Finally
      oleConn.Close
    End Try
  End Sub

I'm modifying rows that will appear in the gridview like so:
Code:
  Private Sub btnSubmit_Click(sender As object, e As EventArgs)
    Dim intRowsAffected As Integer = 0
    Dim oleConn As New OleDbConnection(ConfigurationManager.ConnectionStrings("accdb").ConnectionString)
    Dim oleCMD As New OleDbCommand
    oleCMD.Connection = oleConn
    oleCMD.CommandText = "EXECUTE sproc_unflagevents"
    Dim paramEventRowid As New OleDbParameter
    With paramEventRowid
      .ParameterName = "@eventrowid"
      .OleDbType = OleDbType.Integer
    End With
    oleCMD.Parameters.Add(paramEventRowid)
    Try
      oleCOnn.Open
      Dim dr As GridViewRow
      For Each dr in gvEvents.Rows
        If dr.RowType = DataControlRowType.DataRow Then
          Dim chkbox As CheckBox
          chkbox = dr.FindControl("chkItem")
          If chkbox.Checked = True Then
            paramEventRowid.Value = Integer.parse(gvEvents.DataKeys(dr.RowIndex)("actgevent_rowid"))
            intRowsAffected += oleCMD.ExecuteNonQuery
          End If
        End If
      Next dr
      lblError.Text = intRowsAffected & " Events Unflagged"

      'somehow refresh the gridview here

    Catch ex As Exception
      lblError.Text = ex.Message
    Finally
      oleConn.Close
    End Try
  End Sub

I've tried setting the EnableViewState to false in both the page and the gridview control, but that doesn't seem to work.

What is the best way to get the views to refresh without calling a Response.Redirect to reload the page.

Thanks for help.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
Check out: thread796-1579979

Simply, DG.Refresh()

DG.DataSource = Nothing (this empties the DG)

IHTH

Ron Repp

If gray hair is a sign of wisdom, then I'm a genius.

My newest novel: Wooden Warriors
 
Thanks for the post.

When trying to call gvEvents.Refresh I get:
Code:
Compiler Error Message: BC30456: 'Refresh' is not a member of 'System.Web.UI.WebControls.GridView'.

I have also tried gvEvents.DataBind, but I get a compiler error about the datasource being closed.

Thanks.

"If it's stupid but works, it isn't stupid."
-Murphy's Military Laws
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top