add ID values to Text Box cells of GridView template columns


I use the following code to populate textbox cells in my GridView columns.
I also need to store a unique ID value for each cell. I am currently using the ToolTip to do this
Is there another way that I can embed my ID value in each cell?

    Private Sub GridView1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GridView1.RowDataBound

        Dim oColIndex As Integer
        Dim oDate As String
        Dim oEachDate As Date
        Dim oTemplateColumn As String
        Dim oDateList As String = TryCast(Session("oDateList"), String)
       Dim oLineID_PlusDate As String 'this is eg Line ID 19 apr 2019
        Dim arrDates As Object = Split(oDateList, ",")
        For i As Integer = 0 To UBound(arrDates)
            oColIndex = i + 2
            oTemplateColumn = "D" & CStr(i + 1)
            oEachDate = CDate(arrDates(i))
            oDate = oEachDate.ToString("dd MMM yyyy")
            Me.GridView1.Columns(oColIndex).Visible = True
            If e.Row.RowType = DataControlRowType.Header Then
                Me.GridView1.Columns(oColIndex).HeaderText = oDate
            End If

            'Me.GridView1.Columns(2).Visible = True
            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim D1 As TextBox = CType(e.Row.FindControl(oTemplateColumn), TextBox)
                If Not IsDBNull(e.Row.DataItem(oDate)) Then
                    D1.Text = e.Row.DataItem(oDate)
                End If
               If Not IsDBNull(e.Row.DataItem(oLineID_PlusDate)) Then
                    D.ToolTip = e.Row.DataItem(oLineID_PlusDate)
                End If
            End If
    End Sub
Murray BrownHead DeveloperAsked:
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.

Obadiah ChristopherDeveloper User InterfaceCommented:
In addition to having a textbox in the templatefield, can you add a hiddenfield too? And bind the hiddenfield to oLineID_PlusDate?
Murray BrownHead DeveloperAuthor Commented:
I don't want to do that.
Obadiah ChristopherDeveloper User InterfaceCommented:
okay. Sorry, I can't think of anything else. Just curious what's the scenario? A tooltip will show the value of the id to the end-user in the UI just by moving the mouse cursor.
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.

Murray BrownHead DeveloperAuthor Commented:
the scenario is that I need to run an update when GridView "cell" is changed and the  LinkID is what I need in the update statement. There are currently 30 columns and might be over 300. I don't want to have to then add an additional 300 columns just to hold the ID
Obadiah ChristopherDeveloper User InterfaceCommented:

I was not suggesting to add another column for the hiddenfield. However, it's still upto you to decide if you want to go with this.

                            <asp:TextBox ID="txt1" runat="server"></asp:TextBox>
                            <asp:HiddenField ID="hdn1" runat="server" />

Open in new window

Dim D1 As TextBox = CType(e.Row.FindControl(oTemplateColumn), TextBox)
Dim H1Field As HiddenField = CType(e.Row.FindControl(oTemplateColumn), HiddenField)
                If Not IsDBNull(e.Row.DataItem(oDate)) Then
                    D1.Text = e.Row.DataItem(oDate)
                End If
               If Not IsDBNull(e.Row.DataItem(oLineID_PlusDate)) Then
                    H1Field.Value = e.Row.DataItem(oLineID_PlusDate)
                End If

Open in new window

Why do not you use the ID property of the Textbox ?
 D1.ID = e.Row.DataItem(oLineID_PlusDate) &
  & "_" & CStr(i + 1)

you can then get the linkid by making a split to the ID using "_" as separator

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
Murray BrownHead DeveloperAuthor Commented:
Great idea! Thanks
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.