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

  • Home
  • SEARCH
  • 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 8493629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T23:04:18+00:00 2026-06-10T23:04:18+00:00

How do I only display two colums in my grid view if the gridview

  • 0

How do I only display two colums in my grid view if the gridview is bound in the code behind by an auto generated table? Right now it displays six columns when I only want it to display two?

Here is my .aspx page code:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default2.aspx.vb" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server">

                <columns>
          <asp:boundfield datafield="Drug" headertext="ddddrug"/>
          <asp:boundfield datafield="date" headertext="ddddate"/>

        </columns>


        </asp:GridView>
    </div>
    </form>
</body>
</html>

Here is my code behind code:

Imports System.Data

Partial Class Default2
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    ' auto generated table
        Dim table2 As New DataTable
        ' Create four typed columns in the DataTable.
        table2.Columns.Add("ID", GetType(Integer))
        table2.Columns.Add("Drug", GetType(String))
        table2.Columns.Add("Patient", GetType(String))
        table2.Columns.Add("Date", GetType(DateTime))
        ' Add five rows with those columns filled in the DataTable.
        table2.Rows.Add(25, "Indocin", "David", DateTime.Now)
        table2.Rows.Add(50, "Enebrel", "Sam", DateTime.Now)
        table2.Rows.Add(10, "Hydralazine", "Christoff", DateTime.Now)
        table2.Rows.Add(21, "Combivent", "Janet", DateTime.Now)
        table2.Rows.Add(1100, "Dilantin", "Melanie", DateTime.Now)
        table2.Rows.Add(125, "Indocin", "David", DateTime.Now)
        table2.Rows.Add(150, "Enebrel", "Sam", DateTime.Now)
        table2.Rows.Add(110, "Hydralazine", "Christoff", DateTime.Now)

        GridView1.DataSource = table2

        GridView1.DataBind()

    End Sub

    End Sub
End Class
  • 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-10T23:04:20+00:00Added an answer on June 10, 2026 at 11:04 pm

    Ignore the fact that you have more data than you need. Set AutoGenerateColumns to false. Create BoundColumns for the columns you need to show. Example :

    BoundColumn nameColumn = new BoundColumn();
    nameColumn.DataField = "Drug";
    nameColumn.DataFormatString = "{0}";
    nameColumn.HeaderText = "Drug";
    

    Then add this BoundColumn to gridview.

    GridView1.Columns.Add(nameColumn);
    GridView1.AutoGenerateColumns = false;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I’m trying to display two columns in my table view, one being a title
I have two tables and I want to display only the child ID that
I have tried using the code below but it only display results in Chrome
I am attempting to create a table that will only display one row at
I am trying to display only selected items in list view. public class Mact
As need to display Records in grid view in (ASP.NET) web site. and for
I have 1000 rows of data but need to only display 100 rows at
I'm working with a Facebook Canvas App and I would like to only display
How can I display only selected headers in DataGridView control? For example I have
I want to display only children categories of a particular category. Suppose I have

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.