This is a migrated thread and some comments may be shown as answers.

[Solved] dynamic date columns

1 Answer 160 Views
Grid
This is a migrated thread and some comments may be shown as answers.
L
Top achievements
Rank 1
L asked on 01 Mar 2010, 08:31 AM
hi

I would like to create the columns based on the date.

For example, it is now march and i would like my grid to show 31 columns

01/03    02/03    03/02 all thru 31/03

So when the system date detect it is already 1st april, my grid would create 30 columns

01/04    02/04    03/04    thru 30/04

On conclusion, the grid should create the number of columns based on the number of days in a given month. How should i go about it?

I would like to create an attendence sheet where the rows are the people and the columns are the dates. Thanks

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 01 Mar 2010, 10:21 AM
Hello,

One suggestion to achieve the requirement is by creating DataColumn for the table from code behind. I hope the following example will shed some light on how to achieve this.

C#:
 
    protected void RadGrid2_NeedDataSource(object source, GridNeedDataSourceEventArgs e) 
    { 
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString()); 
        DataSet ds = new DataSet(); 
        string cmdText; 
        cmdText = "Select Name from EmployeeDetails"
        SqlCommand cmd = new SqlCommand(cmdText, conn); 
        SqlDataAdapter adp = new SqlDataAdapter(cmd); 
        adp.Fill(ds); 
        DateTime dt = DateTime.Today.Date; 
 
        int days = System.DateTime.DaysInMonth(DateTime.Now.Year, DateTime.Now.Month);  
 
        for (int i = 0; i < days; i++) 
        { 
            DataColumn col = new DataColumn(i.ToString()); 
            ds.Tables[0].Columns.Add(col); 
        } 
        RadGrid2.DataSource = ds; 
    } 

Regards,
Shinu.
Tags
Grid
Asked by
L
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or