2

I can access the calendar control inside the Gridview Footer Template. But it's not so easy to do the same thing in the EditItem Template

Can anybody suggest how to do this?

I am using 3 controls in the EditItem Template: Calendar, ImageButton, TextBox as well as the Footer Template.

You can use the FindControl method in FooterRow of GridView to make the calendar visible True/False

protected void MyDateInsButton_Click(object sender, EventArgs e)
{
    if (GridView1.FooterRow.FindControl("MyDateInsCalendar").Visible == false)
    {
        GridView1.FooterRow.FindControl("MyDateInsCalendar").Visible = true;
    }
    else
    {
        GridView1.FooterRow.FindControl("MyDateInsCalendar").Visible = false;
    }
}

And get the selected date inside the Footer TextBox

protected void MyDateInsCalendar_SelectionChanged(object sender, EventArgs e)
{        
    Calendar MyCal = (Calendar)sender;

    ((TextBox)GridView1.FooterRow.FindControl("txtinsMyDate")).Text = MyCal.SelectedDate.ToString("d");
    GridView1.FooterRow.FindControl("MyDateInsCalendar").Visible = false;       
}

How do you access the calendar control in the EditItem template to make it visible True and False?

protected void MyUpdButton_Click(object sender, EventArgs e)
{

}

The GridView1_RowUpdating method will work for getting the selected date from the calendar control into the textbox control, but I still want to make the calendar appear and disappear when the user presses the image button.

Any help is appreciated. Thanks.

KenD
  • 5,280
  • 7
  • 48
  • 85
user2912964
  • 33
  • 1
  • 8

1 Answers1

2

You are almost there. Do like this:

protected void MyUpdButton_Click(object sender, EventArgs e)
{
    var MyDateInsCalendar = GridView1.Rows[GridView1.EditIndex].FindControl("MyDateInsCalendar") as Calendar;
    MyDateInsCalendar.Visible = false;
}

And in GridView1_RowEditing, set EditIndex, rebind data:

 protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
 {
      GridView1.EditIndex = e.NewEditIndex;
      GridView1.DataSource = MyDataSource; //Set it to your datasource
      GridView1.DataBind();    
 }

Hope it helps!

afzalulh
  • 7,925
  • 2
  • 26
  • 37
  • I have a follow question. How do you make the VisibleDate property work? – user2912964 Oct 24 '13 at 20:00
  • Here's a good example in MSDN [Calendar.VisibleDate Property](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.calendar.visibledate.aspx). – afzalulh Oct 24 '13 at 20:07