Install control located inside gridview control

I have a GridView and one column of the gridview is a template and I am adding a calendar control.

enter image description here

I want to reach this control using codebehind and edit it, but I don't know how to achieve this. I can achieve above calender, just write calender1 because it is on the page. How can I achieve the calendar inside the gridview.

<asp:Calendar ID="Calendar2" runat="server" SelectedDate="2014-07-08"></asp:Calendar>
<br />
<br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="IsIlanId" DataSourceID="SqlDataSource1" OnRowCommand="GridView1_RowCommand" OnRowDataBound="GridView1_RowDataBound">
        <asp:BoundField DataField="IsIlanId" HeaderText="IsIlanId" InsertVisible="False" ReadOnly="True" SortExpression="IsIlanId" />
        <asp:BoundField DataField="Baslık" HeaderText="Baslık" SortExpression="Baslık" />
        <asp:BoundField DataField="Icerik" HeaderText="Icerik" SortExpression="Icerik" />
        <asp:BoundField DataField="YayinlanmaTarihi" HeaderText="YayinlanmaTarihi" SortExpression="YayinlanmaTarihi" />
        <asp:BoundField DataField="BitisTarihi" HeaderText="BitisTarihi" SortExpression="BitisTarihi" />
        <asp:CheckBoxField DataField="YayindaMi" HeaderText="YayindaMi" SortExpression="YayindaMi" />
        <asp:BoundField DataField="FirmaResim" HeaderText="FirmaResim" SortExpression="FirmaResim" />
        <asp:BoundField DataField="FirmaAdi" HeaderText="FirmaAdi" SortExpression="FirmaAdi" />
        <asp:HyperLinkField DataNavigateUrlFields="IsIlanId" DataNavigateUrlFormatString="Ilan.aspx?id={0}" DataTextField="Baslık" />
        <asp:ImageField DataImageUrlField="FirmaResim">
        <asp:ButtonField ButtonType="Button" CommandName="cmSec" Text="Button" />
        <asp:TemplateField HeaderText="Yayınlanma Tarihi">
                <asp:Calendar VisibleDate='<%# Bind("YayinlanmaTarihi") %>' ID="Calendar1" runat="server" SelectedDate='<%# Bind("YayinlanmaTarihi") %>' ></asp:Calendar>



source to share

1 answer

In case of Grid OnRowDataBound="Grid_RowDataBound"

- add this to GridView1 in aspx file.

protected void Grid_RowDataBound(object sender, GridViewRowEventArgs e)
    if (e.Row.DataItem == null)

    Calendar control= e.Row.FindControl("Calendar1") as Calendar;
    control.Visible = false;


In your case, Control should be Calendar. If you want to click a button, it will be Button

, for Label

Label Control, etc.



All Articles