how to show system_date in changingMode in formview....

Sep 10 2010 8:07 AM
Hi...
i am having insertpage.aspx where i am fetching systemdate but when i am changingMode in for data Insert, systemdate not showing that time and srno also and same as EditMode also.For that reason i can't insert value because its taking null values...... I am sending codebehind code .....please help me out.....
/*********************************************************/

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VehicleApp.library;

public partial class InsertPage : System.Web.UI.Page
{
    library lib = new library();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindFormView();
            Label mydate = (Label)VehicleFormView.Row.FindControl("dateLabel");
            mydate.Text = DateTime.Now.Date.ToShortDateString();
        }

    }
    private void BindFormView()
    {
        if (Session["strTemp"] != null)
        {
            VehicleFormView.DataSource = Session["strTemp"] as DataTable;
            VehicleFormView.DataBind();
        }
        else
        {
            VehicleFormView.DataSource = GetVehicledetail();
            VehicleFormView.DataBind();
        }
    }

    public DataTable GetVehicledetail()
    {
        library lib = new library();

        DataSet MyDataSet = new DataSet();
        DataTable dtable = new DataTable("strTemp");
        dtable.Columns.Add("srno", typeof(string));
        dtable.Columns.Add("cur_date", typeof(string));
        dtable.Columns.Add("official", typeof(string));
        dtable.Columns.Add("private", typeof(string));
        dtable.Columns.Add("empcode", typeof(string));
        dtable.Columns.Add("name", typeof(string));
        dtable.Columns.Add("designation", typeof(string));
        dtable.Columns.Add("department", typeof(string));
        dtable.Columns.Add("vehicle_reqd_on", typeof(string));
        dtable.Columns.Add("from_hours", typeof(string));
        dtable.Columns.Add("to_hours", typeof(string));
        dtable.Columns.Add("visit_place", typeof(string));
        dtable.Columns.Add("vehicle_rpt_person", typeof(string));
        dtable.Columns.Add("vehicle_rpt_location", typeof(string));
        dtable.Columns.Add("purpose", typeof(string));
        dtable.Columns.Add("vehicle_no", typeof(string));
        dtable.Columns.Add("driver_name", typeof(string));
        dtable.Columns.Add("departure_time", typeof(string));
        dtable.Columns.Add("departure_kms_reading", typeof(string));
        dtable.Columns.Add("arrival_time", typeof(string));
        dtable.Columns.Add("arrival_kms_reading", typeof(string));

        DataColumn[] dc = new DataColumn[1];
        dc[0] = dtable.Columns["srno"];

        dtable.PrimaryKey = dc;
        dtable.Columns["srno"].AutoIncrement = true;
        dtable.Columns["srno"].AutoIncrementSeed = 1;


        DataRow dr = dtable.NewRow();
         for (int i = 1; i <= 19; i++)
            {
                dr[i] = "";
            }
            dtable.Rows.Add(dr);
            MyDataSet.Tables.Add(dtable);
            VehicleFormView.DataSource = MyDataSet;
            VehicleFormView.DataBind();
            Session["strTemp"] = dtable;
            return dtable;
            
    }

    protected void VehicleFormView_PageIndexChanging(object sender, FormViewPageEventArgs e)
    {

        VehicleFormView.PageIndex = e.NewPageIndex;
        BindFormView();
    }

    protected void VehicleFormView_ModeChanging(object sender, FormViewModeEventArgs e)
    {
        if (e.NewMode.ToString() == "Edit")
        {
            VehicleFormView.ChangeMode(e.NewMode);
        }
        else if (e.NewMode.ToString() == "Insert")
        {
            VehicleFormView.ChangeMode(e.NewMode);
        }
        else

            VehicleFormView.ChangeMode(e.NewMode);

        BindFormView();
    }

    protected void VehicleFormView_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        library lib = new library();
        DataTable dt = Session["strTemp"] as DataTable;
        DataRow dr = dt.NewRow();


        dr[1] = ((TextBox)VehicleFormView.FindControl("cur_date")).Text.Trim();
        dr[2] = ((TextBox)VehicleFormView.FindControl("official")).Text.Trim();
        dr[3] = ((TextBox)VehicleFormView.FindControl("private")).Text.Trim();
        dr[4] = ((TextBox)VehicleFormView.FindControl("empcode")).Text.Trim();
        dr[5] = ((TextBox)VehicleFormView.FindControl("name")).Text.Trim();
        dr[6] = ((TextBox)VehicleFormView.FindControl("designation")).Text.Trim();
        dr[7] = ((TextBox)VehicleFormView.FindControl("department")).Text.Trim();
        dr[8] = ((TextBox)VehicleFormView.FindControl("vehicle_reqd_on")).Text.Trim();
        dr[9] = ((TextBox)VehicleFormView.FindControl("from_hours")).Text.Trim();
        dr[10] = ((TextBox)VehicleFormView.FindControl("to_hours")).Text.Trim();
        dr[11] = ((TextBox)VehicleFormView.FindControl("visit_place")).Text.Trim();
        dr[12] = ((TextBox)VehicleFormView.FindControl("vehicle_rpt_person")).Text.Trim();
        dr[13] = ((TextBox)VehicleFormView.FindControl("vehicle_rpt_location")).Text.Trim();
        dr[14] = ((TextBox)VehicleFormView.FindControl("purpose")).Text.Trim();
        dr[15] = ((TextBox)VehicleFormView.FindControl("vehicle_no")).Text.Trim();
        dr[16] = ((TextBox)VehicleFormView.FindControl("driver_name")).Text.Trim();
        dr[17] = ((TextBox)VehicleFormView.FindControl("departure_time")).Text.Trim();
        dr[18] = ((TextBox)VehicleFormView.FindControl("departure_kms_reading")).Text.Trim();
        dr[19] = ((TextBox)VehicleFormView.FindControl("arrival_time")).Text.Trim();
        dr[20] = ((TextBox)VehicleFormView.FindControl("arrival_kms_reading")).Text.Trim();
        
        
        dt.Rows.Add(dr);
        Session["strTemp"] = dt;
        VehicleFormView.ChangeMode(FormViewMode.ReadOnly);
        BindFormView();

    }

    protected void VehicleFormView_ItemUpdating(object sender, FormViewUpdateEventArgs e)
    {
        string srno = VehicleFormView.DataKey.Value.ToString();
        DataTable dt = Session["strTemp"] as DataTable;
        DataRow dr;
        dr = dt.NewRow();
        dr = dt.Rows.Find(srno);


        dr[1] = ((TextBox)VehicleFormView.FindControl("cur_date")).Text;
        dr[2] = ((TextBox)VehicleFormView.FindControl("official")).Text;
        dr[3] = ((TextBox)VehicleFormView.FindControl("private")).Text;
        dr[4] = ((TextBox)VehicleFormView.FindControl("empcode")).Text;
        dr[5] = ((TextBox)VehicleFormView.FindControl("name")).Text;
        dr[6] = ((TextBox)VehicleFormView.FindControl("designation")).Text;
        dr[7] = ((TextBox)VehicleFormView.FindControl("department")).Text;
        dr[8] = ((TextBox)VehicleFormView.FindControl("vehicle_reqd_on")).Text;
        dr[9] = ((TextBox)VehicleFormView.FindControl("from_hours")).Text;
        dr[10] = ((TextBox)VehicleFormView.FindControl("to_hours")).Text;
        dr[11] = ((TextBox)VehicleFormView.FindControl("visit_place")).Text;
        dr[12] = ((TextBox)VehicleFormView.FindControl("vehicle_rpt_person")).Text;
        dr[13] = ((TextBox)VehicleFormView.FindControl("vehicle_rpt_location")).Text;
        dr[14] = ((TextBox)VehicleFormView.FindControl("purpose")).Text;
        dr[15] = ((TextBox)VehicleFormView.FindControl("vehicle_no")).Text;
        dr[16] = ((TextBox)VehicleFormView.FindControl("driver_name")).Text;
        dr[17] = ((TextBox)VehicleFormView.FindControl("departure_time")).Text;
        dr[18] = ((TextBox)VehicleFormView.FindControl("departure_kms_reading")).Text;
        dr[19] = ((TextBox)VehicleFormView.FindControl("arrival_time")).Text;
        dr[20] = ((TextBox)VehicleFormView.FindControl("arrival_kms_reading")).Text;
        dt.GetChanges();
        Session["strTemp"] = dt;
        VehicleFormView.ChangeMode(FormViewMode.ReadOnly);
        BindFormView();

    }

    protected void VehicleFormView_ItemDeleting(object sender, FormViewDeleteEventArgs e)
    {
        string srno = VehicleFormView.DataKey.Value.ToString();
        DataTable dt = Session["strTemp"] as DataTable;
        DataRow dr;
        dr = dt.NewRow();
        dt.Rows.Find(srno).Delete();
        dt.GetChanges();
        Session["strTemp"] = dt;
        VehicleFormView.ChangeMode(FormViewMode.ReadOnly);
        BindFormView();
    }

Please check the Insert,update and  function  not working properly. whatt exactly i am doing is i am working on 3-tier architecture where creating provider for database,library for presentation and calling Library in .aspxPage.

please someone help me.....please


/********************************************************/