Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How can i change column name in datagrid

How can i change column name in datagrid

Scheduled Pinned Locked Moved ASP.NET
cssdatabasehelpquestion
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    www Developerof NET
    wrote on last edited by
    #1

    Hi all, I am using a datagrid to display some data.The problem is i want to display my own column name rather than those in database.I am using data adapter and dataset to fill data. Also how can i show only date in the data grid when the contents in the database is date time.It shows date as well as 12AM in addition which i haven`t inserted.

    P J R 3 Replies Last reply
    0
    • W www Developerof NET

      Hi all, I am using a datagrid to display some data.The problem is i want to display my own column name rather than those in database.I am using data adapter and dataset to fill data. Also how can i show only date in the data grid when the contents in the database is date time.It shows date as well as 12AM in addition which i haven`t inserted.

      P Offline
      P Offline
      Pradipta Basu
      wrote on last edited by
      #2

      use this <asp:TemplateColumn HeaderText="Date"> <ItemTemplate"> <# FormatDate(DataBinder.Eval(Container.DataItem, "DBDate")) %"> <ItemTemplate"> </asp:TemplateColumn"> Use a TemplateColumn as shown above where DBDate is your database data field. FormatDate is your own function to format date. The function can be like this shown below. public static string FormatDate(object oInput) { if(oInput != null) { if(oInput != DBNull.Value) return ((DateTime)oInput).ToString("MM-dd-yy"); else return string.Empty; } else return string.Empty; } Hope this will help

      Pradipta Basu

      W 1 Reply Last reply
      0
      • P Pradipta Basu

        use this <asp:TemplateColumn HeaderText="Date"> <ItemTemplate"> <# FormatDate(DataBinder.Eval(Container.DataItem, "DBDate")) %"> <ItemTemplate"> </asp:TemplateColumn"> Use a TemplateColumn as shown above where DBDate is your database data field. FormatDate is your own function to format date. The function can be like this shown below. public static string FormatDate(object oInput) { if(oInput != null) { if(oInput != DBNull.Value) return ((DateTime)oInput).ToString("MM-dd-yy"); else return string.Empty; } else return string.Empty; } Hope this will help

        Pradipta Basu

        W Offline
        W Offline
        www Developerof NET
        wrote on last edited by
        #3

        Thank you. This has helped me a lot.

        1 Reply Last reply
        0
        • W www Developerof NET

          Hi all, I am using a datagrid to display some data.The problem is i want to display my own column name rather than those in database.I am using data adapter and dataset to fill data. Also how can i show only date in the data grid when the contents in the database is date time.It shows date as well as 12AM in addition which i haven`t inserted.

          J Offline
          J Offline
          jeam_yang
          wrote on last edited by
          #4

          :-OYou can use "select customer as my_lovername from table_name" Then column will show my_lovername, wish it can help you! jeam

          1 Reply Last reply
          0
          • W www Developerof NET

            Hi all, I am using a datagrid to display some data.The problem is i want to display my own column name rather than those in database.I am using data adapter and dataset to fill data. Also how can i show only date in the data grid when the contents in the database is date time.It shows date as well as 12AM in addition which i haven`t inserted.

            R Offline
            R Offline
            RichardGrimmer
            wrote on last edited by
            #5

            Define a collection in the grid, then add column definitions, including the HeaderText attribute :) "Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups