Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi All,

I want to display grid view total rows based on the "From and To" calendar duration days count.

ex:
Selected From : 20-Nov-2014 and To 22-Nov-2014 dates.

I am calculating total days duration between calendar selection. Total count is 3 days.
So that i want to display gridview with 3 rows.

i am calculating number of days total like below:
C#
DateTime Fromdate = Convert.ToDateTime(txtfromDate.Text);
DateTime Todate = Convert.ToDateTime(txtToDate.Text);
TimeSpan diff = Todate - Fromdate;
double Nodays = diff.TotalDays + 1;

List<DateTime> days = new List<DateTime>();
for (int i = 1; i <= Nodays; i++)
{
    days.Add(Fromdate.AddDays(i));
}

How to display gridview rows ?

Thanks and Regards,
Krishna.
Posted
Updated 19-Nov-14 22:30pm
v3
Comments
Sinisa Hajnal 20-Nov-14 2:19am    
Are you actually asking us how to add rows to the gridview?
murkalkiran 20-Nov-14 2:27am    
you want display empty 3 rows ?
[no name] 20-Nov-14 3:35am    
Not empty rows, i need to display data from db. If days duration difference is 2 i need to display 2 rows with data.Before getting data i want to display rows first.
Abid Shk 20-Nov-14 5:04am    
first u want to show no of rows in grid based on selection date difference then want to fetch data from db if no of rows in grid and ur db data row not match.
Suppose if 2 entries in same date then how will u display it

In sql query mention(number of rows).

Example: SELECT TOP 3 * from ur tablename
 
Share this answer
 
Comments
George Jonsson 20-Nov-14 4:32am    
This is not an answer to the question.
Hi All,

I got solution.Please refer below. Thank you for all..

C#
  DataTable dt = new DataTable();
           

            dt.Columns.Add(new DataColumn("RowNumber", typeof(string)));
            dt.Columns.Add(new DataColumn("Day", typeof(string)));
            dt.Columns.Add(new DataColumn("Date", typeof(string)));
            dt.Columns.Add(new DataColumn("Allocation", typeof(string)));
            dt.Columns.Add(new DataColumn("Single Room Rate", typeof(string)));
            dt.Columns.Add(new DataColumn("Double Room Rate", typeof(string)));
            dt.Columns.Add(new DataColumn("Stop Sell", typeof(string)));

            DateTime Fromdate = Convert.ToDateTime(txtfromDate.Text);
            DateTime Todate = Convert.ToDateTime(txtToDate.Text);
            TimeSpan diff = Todate - Fromdate;
            double Nodays = diff.TotalDays + 1;
            int Noday = Convert.ToInt32(Nodays);
            List<datetime> days = new List<datetime>();
            for (int i = 1; i <= Noday; i++)
            {
                days.Add(Fromdate.AddDays(i));

                DataRow dr = null;

                dr = dt.NewRow();
                dr["RowNumber"] = i;
                dr["Day"] = string.Empty;
                dr["Date"] = string.Empty;
                dr["Allocation"] = string.Empty;
                dr["Single Room Rate"] = string.Empty;
                dr["Double Room Rate"] = string.Empty;
                dr["Stop Sell"] = string.Empty;
                dt.Rows.Add(dr);
               
                //Store the DataTable in ViewState
                ViewState["CurrentTable"] = dt;
                Gridview1.DataSource = dt;
                Gridview1.DataBind();               

</datetime></datetime>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900