I've got a DataSet that shows a table through Gridview, and the same DataSet also creates a graph. But my problem is that e.g. Date format is different for both, so I was wondering can you change format in a GridView populated by a DataSet?

For the graph date has to be: April 2010
For the table(gridview) date has to be: 2010/04/31

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
        {
            DataSet ds = GetTable();
            outputView.DataSource = ds;
            outputView.DataBind();
}
}

public DataSet GetTable()
    {
        string f_id = Request.QueryString["f_id"];
        string strConnString =
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|calculator.mdb";

        OleDbConnection con = new OleDbConnection(strConnString);

        con.Open();

            // read from form_input table
        string strQuery = "select * from form_input where f_id=" + f_id;
        OleDbCommand cmd = new OleDbCommand(strQuery, con);
        OleDbDataReader reader = cmd.ExecuteReader();
        reader.Read();
        string start_str = reader["start"].ToString();
        DateTime start = DateTime.Parse(start_str);
        string end_str = reader["completion"].ToString();
        DateTime end = DateTime.Parse(end_str);
        string cost = reader["cost"].ToString();
        double b = double.Parse(cost);
        string validDay_str = reader["validation"].ToString();
        int validDay = Int32.Parse(validDay_str);
        string code = reader["code"].ToString();
        string holiday_str = reader["holiday"].ToString();
        int holiday = Int32.Parse(holiday_str);

            // read from alpha_beta table
        string strQuery2 = "select * from alpha_beta where code=" + code;
        OleDbCommand cmd2 = new OleDbCommand(strQuery2, con);
        OleDbDataReader reader2 = cmd2.ExecuteReader();
        reader2.Read();
        string construction_a_str = reader2["construction_a"].ToString();
        string construction_b_str = reader2["construction_b"].ToString();
        string top_a_str = reader2["top_a"].ToString();
        string top_b_str = reader2["top_b"].ToString();
        string bottom_a_str = reader2["bottom_a"].ToString();
        string bottom_b_str = reader2["bottom_b"].ToString();

            // alpha_beta values
        double construction_a = double.Parse(construction_a_str);
        double construction_b = double.Parse(construction_b_str);
        double top_a = double.Parse(top_a_str);
        double top_b = double.Parse(top_b_str);
        double bottom_a = double.Parse(bottom_a_str);
        double bottom_b = double.Parse(bottom_b_str);

            // display
        DataSet ds = new DataSet();
        DataTable dt = ds.Tables.Add("Table");
        dt.Columns.Add(new DataColumn("Valuation Date", typeof(string)));
        dt.Columns.Add(new DataColumn("Construction Cash Flow", typeof(int)));
        dt.Columns.Add(new DataColumn("Upper Probability Limit", typeof(int)));
        dt.Columns.Add(new DataColumn("Lower Probability Limit", typeof(int)));

            // fill rows
        foreach (DateTime valuationDate in GetDates(start, end, validDay))
        {
            int numberOfDays = 0;
            if (valuationDate.Month == 12 || valuationDate.Month == 01)
            {
                numberOfDays = 14;
            }
            current += numberOfDays;

            DataRow row = dt.NewRow();
            row["Valuation Date"] = valuationDate.ToString("MMMM yyyy");
            row["Construction Cash Flow"] = Calculation(current, holiday, validDay, b, valuationDate, start, end, construction_a, construction_B);
            row["Upper Probability Limit"] = Calculation(current, holiday, validDay, b, valuationDate, start, end, top_a, top_B);
            row["Lower Probability Limit"] = Calculation(current, holiday, validDay, b, valuationDate, start, end, bottom_a, bottom_B);
            dt.Rows.Add(row);

        }

        reader2.Close();
        reader.Close();
        con.Close();
        return ds;
    }

I've got a DataSet that shows a table through Gridview, and the same DataSet also creates a graph. But my problem is that e.g. Date format is different for both, so I was wondering can you change format in a GridView populated by a DataSet?

For the graph date has to be: April 2010
For the table(gridview) date has to be: 2010/04/31

protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
        {
            DataSet ds = GetTable();
            outputView.DataSource = ds;
            outputView.DataBind();
}
}

public DataSet GetTable()
    {
        string f_id = Request.QueryString["f_id"];
        string strConnString =
            "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|calculator.mdb";

        OleDbConnection con = new OleDbConnection(strConnString);

        con.Open();

            // read from form_input table
        string strQuery = "select * from form_input where f_id=" + f_id;
        OleDbCommand cmd = new OleDbCommand(strQuery, con);
        OleDbDataReader reader = cmd.ExecuteReader();
        reader.Read();
        string start_str = reader["start"].ToString();
        DateTime start = DateTime.Parse(start_str);
        string end_str = reader["completion"].ToString();
        DateTime end = DateTime.Parse(end_str);
        string cost = reader["cost"].ToString();
        double b = double.Parse(cost);
        string validDay_str = reader["validation"].ToString();
        int validDay = Int32.Parse(validDay_str);
        string code = reader["code"].ToString();
        string holiday_str = reader["holiday"].ToString();
        int holiday = Int32.Parse(holiday_str);

            // read from alpha_beta table
        string strQuery2 = "select * from alpha_beta where code=" + code;
        OleDbCommand cmd2 = new OleDbCommand(strQuery2, con);
        OleDbDataReader reader2 = cmd2.ExecuteReader();
        reader2.Read();
        string construction_a_str = reader2["construction_a"].ToString();
        string construction_b_str = reader2["construction_b"].ToString();
        string top_a_str = reader2["top_a"].ToString();
        string top_b_str = reader2["top_b"].ToString();
        string bottom_a_str = reader2["bottom_a"].ToString();
        string bottom_b_str = reader2["bottom_b"].ToString();

            // alpha_beta values
        double construction_a = double.Parse(construction_a_str);
        double construction_b = double.Parse(construction_b_str);
        double top_a = double.Parse(top_a_str);
        double top_b = double.Parse(top_b_str);
        double bottom_a = double.Parse(bottom_a_str);
        double bottom_b = double.Parse(bottom_b_str);

            // display
        DataSet ds = new DataSet();
        DataTable dt = ds.Tables.Add("Table");
        dt.Columns.Add(new DataColumn("Valuation Date", typeof(string)));
        dt.Columns.Add(new DataColumn("Construction Cash Flow", typeof(int)));
        dt.Columns.Add(new DataColumn("Upper Probability Limit", typeof(int)));
        dt.Columns.Add(new DataColumn("Lower Probability Limit", typeof(int)));

            // fill rows
        foreach (DateTime valuationDate in GetDates(start, end, validDay))
        {
            int numberOfDays = 0;
            if (valuationDate.Month == 12 || valuationDate.Month == 01)
            {
                numberOfDays = 14;
            }
            current += numberOfDays;

            DataRow row = dt.NewRow();
            row["Valuation Date"] = valuationDate.ToString("MMMM yyyy");
            row["Construction Cash Flow"] = Calculation(current, holiday, validDay, b, valuationDate, start, end, construction_a, construction_B);
            row["Upper Probability Limit"] = Calculation(current, holiday, validDay, b, valuationDate, start, end, top_a, top_B);
            row["Lower Probability Limit"] = Calculation(current, holiday, validDay, b, valuationDate, start, end, bottom_a, bottom_B);
            dt.Rows.Add(row);

        }

        reader2.Close();
        reader.Close();
        con.Close();
        return ds;
    }

you can use something like <%#Eval("your date","{specify formate of date}") %> inside inline code of Gridview of page.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.