How can i change column name in datagrid
-
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.
-
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.
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 helpPradipta 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 helpPradipta Basu
Thank you. This has helped me a lot.
-
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.
-
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.
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