views:

744

answers:

3

Hi, In my application I am creating rows and columns dynamically. I created a column of type System.DateTime. After this i want to display datetimepicker control for all rows in that column.

I created a column using

dataTable.Columns.Add("CreatedOn", Type.GetType("System.DateTime"));


and i am adding rows as

foreach(String filename ......)
 dataTable_FileProperty.Rows.Add(filename,//here i want to add dateTimePicker

So, what is a solution for this.

EDIT: Please provide some code snippet. I am new to C#.net.
Thanks.

+1  A: 

use the item template of the gridview and place a datetimepicker there. A good example is here

For implementing it you have to implement the ITemplate interface.

Another example is this

An easy implementation of it is given in this msdn article. But the code is in VB.net.

HotTester
The solution provided by you is so complex. I am waiting for easy one. anyways Thanks. :)
Jessica
i have updated an easy implementation link of msdn. Hope it helps.
HotTester
A: 

DataTable.Rows contains data, i.e file name, date, some strings.

GridView.Columns contains controls to display data.

So if you're using DataRowCollection.Add(Object[]) :

DataTable DataTable1 = new DataTable();
DataTable1.Columns.AddRange(
     new DataColumn[] {
          new DataColumn("file", typeof(string)),
          new DataColumn("date", typeof(DateTime)) });

foreach (string f in System.IO.Directory.GetFiles(@"c:\windows"))
    DataTable1.Rows.Add(f, System.IO.File.GetCreationTime(f));

GridView1.DataSource = DataTable1;
GridView1.DataBind();

And the markup of GridView:

<asp:GridView runat="server" ID="GridView1" AutoGenerateColumns="false">
    <Columns>
        <asp:BoundField HeaderText="File" DataField="file" />
        <asp:TemplateField HeaderText="Date">
            <ItemTemplate>
                <asp:Calendar runat="server" ID="Calendar1" SelectedDate='<%# Bind("date") %>' />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Also you need to read more about Calendar.SelectedDate and Calendar.VisibleDate

abatishchev
+1  A: 

By default you have just these columns available for you:

DataGridViewTextBoxColumn, DataGridViewCheckBoxColumn, DataGridViewImageColumn, DataGridViewButtonColumn, DataGridViewComboBoxColumn, DataGridViewLinkColumn

If you want to show a datetimepicker control then you have to implement a custom column.

Check this out: http://msdn.microsoft.com/en-us/library/7fb61s43.aspx

Hope this helps.

Raja