tryng RowDataBound event to bind a TemplateField to a GridView in VB2015/ASP

I have a working GridView bound to SQL query, and I'm adding onto it, a new TemplateField  via:
                    <asp:BoundField DataField="spid" HeaderText="spid" SortExpression="spid" />
                    <asp:BoundField DataField="Login" HeaderText="Login" ReadOnly="True" SortExpression="Login" />
                    <asp:BoundField DataField="DB" HeaderText="DB" ReadOnly="True" SortExpression="DB" />
                    <asp:BoundField DataField="SERVER" HeaderText="SERVER" SortExpression="SERVER"/>
                    <asp:BoundField DataField="LOGIN TIME" HeaderText="LOGIN TIME" ReadOnly="True" SortExpression="LOGIN TIME"/>
                    <asp:BoundField DataField="USER COUNT" HeaderText="USER COUNT" ReadOnly="True" SortExpression="USER COUNT" visible="FALSE"/>
                    <%--<asp:BoundField DataField="siteName" HeaderText="SITE" SortExpression="siteName"/>--%>
                    <asp:TemplateField HeaderText="SiteName" SortExpression="Sitename"> 
                            <asp:Label ID="lblSiteName" runat="server"></asp:Label> 


Open in new window

I'm trying to use:
    Protected Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound

Open in new window

to then, populate the new column cells with text, but I notice that when stepping through the code, if I highlight GridView1
in as seen below:
as you can see, the GridView has NO rows.
So, somehow, I'm losing the bindings before entering the even handler...?
Richard GouetteIT ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ryan ChongSoftware Team LeadCommented:
as you can see, the GridView has NO rows.
So, somehow, I'm losing the bindings before entering the even handler...?

Check this article for the info:

GridView.RowDataBound Event

The RowDataBound event is raised when a data row (represented by a GridViewRow object) is bound to data in the GridView control. This enables you to provide an event-handling method that performs a custom routine, such as modifying the values of the data bound to the row, whenever this event occurs.

it means RowDataBound event will be triggered when the data row is generating, in the event that when the RowDataBound event is first raised, your GridView is empty (no row)
Richard GouetteIT ManagerAuthor Commented:
I seem to be struggling to know where I would set cells(7).text  values, and have them bound to the GridView1..

Any further direction?

Ryan ChongSoftware Team LeadCommented:
I seem to be struggling to know where I would set cells(7).text  values, and have them bound to the GridView1..
is this related to your question? what is cells(7).text? how you want it bound to the GridView1?
Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

Richard GouetteIT ManagerAuthor Commented:
is this related to your question?

what is cells(7).text?

how you want it bound to the GridView1?

Perhaps the better question might be:
"When should I bind a new column of data, so that it is displayed with the SQL bound data?"
Ryan ChongSoftware Team LeadCommented:
ok, so knowing you got a template field with a label control that need to be bounded, so what data to bind to this template field?

from your codes in your question, it seems that you're reading the field's value instead of populating the value into it?
Richard GouetteIT ManagerAuthor Commented:
I'm trying to write in values in this way:

           For i = 0 To GridView1.Rows.Count - 1
                         nameToCheck = GridView1.Rows(i).Cells(1).Text
                         nameToCheck = Trim(nameToCheck)
                         lb1.Items.Add(String.Concat(nameToCheck + i.ToString))
                         Select Case nameToCheck
                                   Case "AVALUE"
                                               GridView1.Rows(i).Cells(6).Text = "ME"
                                   Case "ANOTHERVALUE"
                                               GridView1.Rows(i).Cells(6).Text = "ME"

Open in new window

Ryan ChongSoftware Team LeadCommented:
any reason why you want to do a looping on:

nameToCheck = GridView1.Rows(i).Cells(1).Text


let's say if you want to verify the second column (index as 1)'s value and place a custom value in cell 7 (index as 6), you still can use the RowDataBound event, perhaps in this way:

Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim nameToCheck As String = e.Row.Cells(1).Text
            If (Convert.ToInt32(nameToCheck) >= 5) Then
                e.Row.Cells(6).Text = "ME"
                e.Row.Cells(6).Text = "NOT ME"
            End If
        End If
    End Sub

Open in new window

try customize accordingly

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ryan ChongSoftware Team LeadCommented:
any feedback on this?
Ryan ChongSoftware Team LeadCommented:
suggested solutions should enable asker to address the solution
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.