Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8636459
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:14:06+00:00 2026-06-12T10:14:06+00:00

I have a Gridview which has its datasource set to a DataTable. This has

  • 0

I have a Gridview which has its datasource set to a DataTable. This has been done due to the data required which is not held in a database. Two columns are generated in this fashion. What i need is a third column to have a textbox, so users can enter their comments etc.

My code is

    Dim dt As DataTable = New DataTable
    Dim row As DataRow

    ' Generate Columns
    dt.Columns.Add("Col One")
    dt.Columns.Add("Col Two")
    dt.Columns.Add("Textbox Col")

    ' Populate rows with required data
    row = dt.NewRow
    row.Item("Col One") = SomeData
    row.Item("Col Two") = SecondaryData
    row.Item("Textbox Col") = InsertTextbox("data")

    ' Add row to DataTable
    dt.Rows.Add(row)

    gvData.DataSource = dt
    gvData.DataBind()

The above code does exactly what i require except when Inserting the textbox (InsertTextbox). The textbox code is

Private Function InsertTextbox(ByVal TBText As String) As TextBox
    Dim tbox As TextBox = New TextBox

    With tbox
        .Width = 100
        .Height = 25
        .Text = TextboxText
        .ID = TextboxText
    End With

    gvData.Controls.Add(txtbox)

    Return txtbox
End Function

The above code has been changed a few times to see how i could have allowed textboxes to be inserted into a gridview cell.

Currently i get the data back as required but the Textbox Col shows as System.Web.UI.WebControls.TextBox. Adding .Text shows the text (in this case data) but its displayed in a label format meaning you cant enter anything inside it.

Could anyone advise how i could insert a textbox in this fashion?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:14:07+00:00Added an answer on June 12, 2026 at 10:14 am

    Define a Templatefield in the gridview and place a PlaceHolder control inside the Templatefield.

    <asp:GridView ID="GridView1" runat="server" >
       <Columns>
          <asp:TemplateField>
             <ItemTemplate>
                  <asp:PlaceHolder ID="PlaceHolder_InputControl" runat="server" />
             </ItemTemplate>
           </asp:TemplateField>
       </Columns>
    

    Use the RowCreated event to add the textbox dynamically:

    Protected Sub GridView1_RowCreated(sender As Object, e As GridViewRowEventArgs)
    
        If e.Row.RowType = DataControlRowType.DataRow Then
            Dim pc1 As PlaceHolder = DirectCast(e.Row.Cells(0).Controls(1), PlaceHolder)
            Dim tb As TextBox = New TextBox
            With tb
                    .Width = 100
                    .Height = 25
                    .Text = TextboxText
                    .ID = TextboxText
            End With
            pc1.Controls.Add(tb)
        End If
    
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

ok i have a project which has many gridview in its pages... now i
I have been given a task of creating a common Gridview component which has
I have an AspxGridView which has another aspxgridview in its detailrows. The second gridview
I created a GridView in code with a DataTable as its data source which
For example, Lets say that I have a gridview column which has important controls,
I have a GridView in which each row has a custom view. The grid
I have a GridView on a .aspx page with a hidden column which has
I have a gridview within an updatepanel which allows paging and has a linkbutton
I have a GridView which is programatically filled from the DB (not a SqlDataSource
I have a GridView which is databound to an XML Datasource. For one of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.