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:
     
           <columns>
                    <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"> 
                        <ItemTemplate> 
                            <asp:Label ID="lblSiteName" runat="server"></asp:Label> 
                        </ItemTemplate> 
                    </asp:TemplateField>

                  </columns>

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:
  stepCode.PNG
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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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 ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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
https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.rowdatabound(v=vs.110).aspx

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)
0
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?

Thanks,
R
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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?
0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

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

what is cells(7).text?
I THINK I MEANT TO SAY CELLS(6)
THIS SI MEANT TO BE THE NEW COLUMN OF CELLS

how you want it bound to the GridView1?
I AM TRYING TO HAVE THE NEW COLUMN/CELLS BOUND ANYTIME BEFORE THE PAGE IS DISPLAYED

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?"
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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?
0
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"
             Next

Open in new window

0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
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"
            Else
                e.Row.Cells(6).Text = "NOT ME"
            End If
        End If
    End Sub

Open in new window


try customize accordingly
0

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 ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
any feedback on this?
0
Ryan ChongBusiness Systems Analyst , ex-Senior Application EngineerCommented:
suggested solutions should enable asker to address the solution
0
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
ASP.NET

From novice to tech pro — start learning today.