Click here to Skip to main content
15,911,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 2 calendar controls and 1 Gridview control.when user selects date from both controls i display data in the gridview between selected dates months. I have written select query for this. i am displaying 3 colums FileName,UploadDate And ProcessedDate on search button .
Now What i have to do is i want to add calendar control to ProcessedDate column when edit
GridView1_RowEditing
event fires. i am able to put manual date in that filed and save into the database but i want to display calendar control there.

this my aspx page code


<asp:GridView ID="GridView1" runat="server"  DataKeyNames="FileName" CellPadding="6" GridLines="None" CssClass="inline"  AutoGenerateEditButton="True" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit" BackColor="White" BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellSpacing="1" OnRowDataBound="GridView1_RowDataBound">
             <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
             <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
             <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
             <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
             <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
             <SortedAscendingCellStyle BackColor="#F1F1F1" />
             <SortedAscendingHeaderStyle BackColor="#594B9C" />
             <SortedDescendingCellStyle BackColor="#CAC9C9" />
             <SortedDescendingHeaderStyle BackColor="#33276A" />


         </asp:GridView>


C# code
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
           
            GridViewRow row = GridView1.Rows[e.RowIndex];
               //Calendar textName = (Calendar)row.Cells[0].Controls[0];
            //System.Web.UI.WebControls.Calendar Calendar1 = (System.Web.UI.WebControls.Calendar)row.Cells[0].Controls[0];
            //TextBox ProcessedDate = (TextBox)row.FindControl("txtProductName");
            //int PackageDetailsID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Values[0]);
            string FileName = Convert.ToString(GridView1.DataKeys[e.RowIndex].Values[0]);
            string name = (row.Cells[2].Controls[0] as TextBox).Text;
            //string country = (row.Cells[3].Controls[0] as TextBox).Text;
            string constr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
            using (SqlConnection con = new SqlConnection(constr))
            {
                using (SqlCommand cmd = new SqlCommand("UPDATE PackageDetails SET ProcessedDate = @ProcessedDate WHERE FileName = @FileName"))
                //using (SqlCommand cmd = new SqlCommand("UPDATE PackageDetails SET ProcessedDate = '" + Calendar1 + "' WHERE FileName ='" + FileName + "'"))

                {

                    cmd.Parameters.AddWithValue("@FileName", FileName);
                    cmd.Parameters.AddWithValue("@ProcessedDate", name);
                   
                    cmd.Connection = con;
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
            }
            GridView1.EditIndex = -1;
            //this.BindGrid();
            this.BindDataGrid();

        }

        public void BindDataGrid()
        {

            string constr = ConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString;
            using (SqlConnection con = new SqlConnection(constr))
            {

                using (SqlCommand cmd = new SqlCommand("SELECT DISTINCT FileName, UploadDate, ProcessedDate FROM PackageDetails WHERE CONVERT(DATE, UploadDate) BETWEEN @From AND @To", con))
                {
                 
                    using (SqlDataAdapter da = new SqlDataAdapter(cmd))
                    {
                        string date = "";
                        date = CalendarFrom.SelectedDate.ToString("MM-dd-yyyy");
                        string date2 = "";
                        date2 = CalendarTo.SelectedDate.ToString("MM-dd-yyyy");
                        cmd.Parameters.Add("@From", SqlDbType.Date).Value = date;
                        cmd.Parameters.Add("@To", SqlDbType.Date).Value = date2;
                        DataSet ds = new DataSet();
                        da.Fill(ds);
                      
                        GridView1.DataSource = ds;
                        GridView1.DataBind();
                    }
                }
            }

        }

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
       {
           GridView1.EditIndex = e.NewEditIndex;
          //System.Web.UI.WebControls.Calendar Calendar1 = (System.Web.UI.WebControls.Calendar)row.Cells[0].Controls[0];

           //this.BindGrid();
           this.BindDataGrid();
       }


What I have tried:

i have tried using javascript but i didn't get result as i am expecting.
Posted
Updated 27-Feb-17 15:26pm
v2
Comments
Karthik_Mahalingam 27-Feb-17 9:41am    
use jquery date picker which simplifies the job.
Member 12409011 27-Feb-17 9:45am    
i am new to web i don't know how to use jquery to achieve this.
Karthik_Mahalingam 27-Feb-17 21:23pm    
Always use  Reply  button, to post Comments/query to the user, so that the user gets notified and responds to your text.

 
Share this answer
 
Google search is your friend. Using you own CodeProject Question Title: calendar control on gridview column on edit mode in ASP.NET C# - Google[^]

In 2 seconds found this: asp.net - Calendar in gridview edit mode - Stack Overflow[^]
 
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