Click here to Skip to main content
15,920,053 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
public void BindGrid(int rowcount)
   {
       btnsubmit.Visible = true;
       DataTable dt = new DataTable();
       DataRow dr;
       dt.Columns.Add(new System.Data.DataColumn("Employee ID", typeof(String)));
       dt.Columns.Add(new System.Data.DataColumn("Leave Type", typeof(String)));
       dt.Columns.Add(new System.Data.DataColumn("From", typeof(String)));
       dt.Columns.Add(new System.Data.DataColumn("To", typeof(String)));
       dt.Columns.Add(new System.Data.DataColumn("No:of Days", typeof(String)));


       if (ViewState["CurrentData"] != null)
       {
           for (int i = 0; i < rowcount + 1; i++)
           {
               dt = (DataTable)ViewState["CurrentData"];
               if (dt.Rows.Count > 0)
               {
                   dr = dt.NewRow();
                   dr[0] = dt.Rows[0][0].ToString();

               }
           }
           dr = dt.NewRow();
           dr[0] = lblempID.Text;
           dr[1] = ddlleavetype.SelectedItem.Text.ToString();
           dr[2] = txtfrom.Text.ToString();
           dr[3] = txtto.Text.ToString();

           dt.Rows.Add(dr);

       }
       else
       {
           dr = dt.NewRow();
           dr[0] = lblempID.Text;
           dr[1] = ddlleavetype.SelectedItem.Text.ToString();
           dr[2] = txtfrom.Text.ToString();
           dr[3] = txtto.Text.ToString();

           dt.Rows.Add(dr);

       }

       // If ViewState has a data then use the value as the DataSource
       if (ViewState["CurrentData"] != null)
       {
           gvLeave.DataSource = (DataTable)ViewState["CurrentData"];
           gvLeave.DataBind();
       }
       else
       {
           // Bind GridView with the initial data assocaited in the DataTable
           gvLeave.DataSource = dt;
           gvLeave.DataBind();

       }
       // Store the DataTable in ViewState to retain the values
       ViewState["CurrentData"] = dt;


   }
Posted
Updated 18-Nov-13 23:02pm
v2

1 solution

Try this. Hope this helps.

C#
DateTime start = Convert.DateTime(txtfrom.Text.ToString());
DateTime end  = Convert.DateTime(txtto.Text.ToString());

dr[3] = (end-start).Days.ToString();


NOTE: This code is not compiled.
 
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