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];
string FileName = Convert.ToString(GridView1.DataKeys[e.RowIndex].Values[0]);
string name = (row.Cells[2].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"))
{
cmd.Parameters.AddWithValue("@FileName", FileName);
cmd.Parameters.AddWithValue("@ProcessedDate", name);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
GridView1.EditIndex = -1;
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;
this.BindDataGrid();
}
What I have tried:
i have tried using javascript but i didn't get result as i am expecting.