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 9236235
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:14:35+00:00 2026-06-18T07:14:35+00:00

I have a gridview using <asp:BoundField DataField=Comments HeaderText=COMMENTS /> , I would like to

  • 0

I have a gridview using <asp:BoundField DataField="Comments" HeaderText="COMMENTS" />, I would like to only show the first 20 characters in the Commemnt column when the gridview gets populated. Is there way to accomplish this in VB? Thank you.

  • 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-18T07:14:36+00:00Added an answer on June 18, 2026 at 7:14 am

    One way is using the RowDataBound event in codebehind:

    Protected Sub Gridview1_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles Gridview1.RowDataBound
        Select Case e.Row.RowType
            Case DataControlRowType.DataRow
                ' assuming the comments column is the first column '
                If e.Row.Cells(0).Text.Length > 20 Then
                    e.Row.Cells(0).Text = e.Row.Cells(0).Text.Substring(0, 20)
                End If
        End Select
    End Sub
    

    Note that you can access the text on this way only with BoundFields. With TemplateFields you need to use FindControl to get a reference of your controls(f.e. a TextBox).

    If you would use a TemplateField you could also limit the text on the aspx markup:

    <asp:TemplateField HeaderText="Commnents">
    <ItemTemplate>
        <asp:TextBox ID="txtID"  
             MaxLength="20" runat="server" 
             Text='<%# DataBinder.Eval(Container.DataItem, "Comments") %>'>
        </asp:TextBox>
    </ItemTemplate>
    </asp:TemplateField>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a GridView, <asp:GridView ID=GridView1 runat=server AutoGenerateColumns=False DataSourceID=SqlDataSource1> <Columns> <asp:BoundField DataField=LastName HeaderText=LastName SortExpression=LastName
<asp:GridView ID=grid1 runat=server AutoGenerateColumns=False> <Columns> <asp:BoundField DataField='id' HeaderText=Id Visible=False /> <asp:BoundField DataField='Name' Visible=True HeaderText=Full
I have asp:GridView displaying client requests using asp:SqlDataSource . I want to limit displayed
Using asp.net 3.5 Gridview control, visual studio 2008. I have played with all the
Using ASP.NET VB, I have a form with some text boxes and a Gridview.
I have an ASP.NET(2.0 using C#) web app, in which I have a gridview.
I have created a gridview using toolbox in c#, it is able to show
I have a simple grid view like this : <asp:GridView ID=gv_userActivities runat=server AutoGenerateColumns=False> <Columns>
I am using ASP.NET Membership and Linq. I have a problem here: I show
I'm displaying a GridView using the following markup in my default.aspx : <Columns> <asp:BoundField

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.