The code below populates a gridview control which has all its rows' ForeColor set to Drawing.Color.Blue. The Page_Load routine runs fine as the gridview appears with all the right data in Blue. Upon clicking btnSelect, the debugger starts off in Page_Load, skips over the subroutine because it is a postback, then jumps into the btnSelect_Click code, sets all the gv.Rows ForeColor to Red and exits. The page reappears from debug and the gridview ForeColor is still Blue!! I cannot figure this one out. Anybody out there have any (polite) suggestions? My first experience with the gridview.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Not Page.IsPostBack) Then
cn = Session("Connection")
If (cn.State.ToString = "Closed") Then cn.Open()
cmd = New SqlCommand("SelectAllStores", cn)
cmd.CommandType = Data.CommandType.StoredProcedure
sdr = cmd.ExecuteReader
If (sdr.HasRows) Then
gv.DataSource = sdr
gv.DataBind()
End If
sdr.Close()
cmd.Dispose()
End If
End Sub
Protected Sub btnSelect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles btnSelect.Click
Dim i As Integer
For i = 0 To gv.Rows.Count - 1
gv.Rows(i).ForeColor = Drawing.Color.Red