GridView strange behaviour
<p>I have problem on page bellow, in gdvCar_DataBound I add three buttons, when I click on any of them, page go to postback but doesn't enter in gdvCar_RowCommand and then that buttons ( and images that I also add in gdvCar_DataBound) disaper. Grid is then full like gdvCar_DataBound isn't execute. My question is why it doesn't enter at  gdvCar_RowCommand ?</p>

<pre><code>using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HMS.library;
using System.Data.SqlClient;

namespace HMS
{
    public partial class Cars : System.Web.UI.Page
    {
        #region fields
        private const Int16 PageId = 1;
        private String connectionString = "Server=localhost;Database=hms_test;Trusted_Connection=True;";
        String[] filters = null;
        #endregion

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!IsPostBack)
            {
                FillProducer();
                FillModel(Convert.ToInt16(ddlProducer.SelectedValue));
                RestoreFilters();
                FillGrid();


            }


        }


        #region events
        protected void ddlProducer_Changed(object sender, EventArgs e)
        {
            if (ddlProducer.SelectedValue != "0")
            {
                ddlModel.Enabled = true;
                FillModel(Convert.ToInt16(ddlProducer.SelectedValue));
            }
            else
            {
                ddlModel.SelectedValue = "0";
                ddlModel.Enabled = false;
            }
            upSearch.Update();
        }

        protected void gdvCar_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            switch (e.CommandName)
            {
                case "Reserve":
                    {
                        pnlReserve.Visible = true;
                        break;
                    }
                case "Phone":
                    {
                        break;
                    }
                case "Email":
                    {
                        break;
                    }

            }

        }

        protected void gdvCar_DataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {

                String id = e.Row.Cells[0].Text;
                Image img = new Image();
                img.ID = "img_one" + id;
                img.Width = 96;
                img.Height = 96;
                img.ImageUrl = "images/car/" + e.Row.Cells[7].Text;
                e.Row.Cells[7].Controls.Add(img);
                img = new Image();
                img.ID = "img_two" + id;
                img.Width = 96;
                img.Height = 96;
                img.ImageUrl = "images/car/" + e.Row.Cells[8].Text;
                e.Row.Cells[8].Controls.Add(img);
                img = new Image();
                img.ID = "img_three" + id;
                img.Width = 96;
                img.Height = 96;
                img.ImageUrl = "images/car/" + e.Row.Cells[9].Text;
                e.Row.Cells[9].Controls.Add(img);


                ImageButton imbReserve = new ImageButton();
                imbReserve.ID = "res" + id;
                imbReserve.Enabled = true;
                imbReserve.Width = 48; imbReserve.Height = 48;
                imbReserve.ToolTip = "Reserve"; imbReserve.AlternateText = "Reserve";
                imbReserve.ImageUrl = "images/icons/key.gif";
                imbReserve.CommandName = "Reserve";
                imbReserve.CommandArgument = id;
                e.Row.Cells[10].Controls.Add(imbReserve);


                ImageButton imbPhone = new ImageButton();
                imbPhone.ID = "phone" + id;
                imbPhone.Enabled = true;
                imbPhone.Width = 48; imbPhone.Height = 48;
                imbPhone.ToolTip = "Reserve by phone"; imbPhone.AlternateText = "Phone";
                imbPhone.ImageUrl = "images/icons/phone.jpg";
                imbPhone.CommandName = "Phone";
                imbPhone.CommandArgument = id;
                e.Row.Cells[11].Controls.Add(imbPhone);

                ImageButton imbEmail = new ImageButton();
                imbEmail.ID = "email" + id;
                imbEmail.Enabled = true;
                imbEmail.Width = 48; imbEmail.Height = 48;
                imbEmail.ToolTip = "Reserve by email"; imbEmail.AlternateText = "Email";
                imbEmail.ImageUrl = "images/icons/email.jpg";
                imbEmail.CommandName = "Email";
                imbEmail.CommandArgument = id;
                e.Row.Cells[12].Controls.Add(imbEmail);





            }
        }

        protected void imbSearch_Click(object sender, ImageClickEventArgs e)
        {
            StoreFilters();
            FillGrid();

        }
        #endregion

        #region functions
        private void FillProducer()
        {
            hmsDataContext hms = new hmsDataContext();
            var source = from o in hms.producer_cars
                         orderby o.name
                         select new
                         {
                             o.id,
                             o.name
                         };
            foreach (var temp in source)
                ddlProducer.Items.Add(new ListItem(temp.name, temp.id.ToString()));
            ddlProducer.Items.Insert(0, (new ListItem("all producers", "0")));
        }

        private void FillModel(int producer_id)
        {
            hmsDataContext hms = new hmsDataContext();
            var source = from o in hms.model_cars
                         from p in hms.producer_cars
                         where o.producer_car_id == producer_id &amp;&amp; p.id == producer_id
                         orderby o.name
                         select new
                         {
                             o.id,
                             o.name
                         };
            ddlModel.Items.Clear();
            foreach (var temp in source)
                ddlModel.Items.Add(new ListItem(temp.name, temp.id.ToString()));
            ddlModel.Items.Insert(0, (new ListItem("all producers", "0")));
        }

        private void FillGrid()
        {
            SqlConnection conn = new SqlConnection(connectionString);
            String command = @"SELECT car.id AS id, car.price as price, car.weight as weight,
car.year as year, producer_car.name as producer, model_car.name as model, car.number_seats as number_seats, car.photo_one as photo_one,car.photo_two as photo_two,car.photo_three as photo_three, '' as reserver,'' as phone,'' as email
FROM car INNER JOIN model_car on car.model_car_id=model_car.id
INNER JOIN producer_car on model_car.producer_car_id=producer_car.id";
            if(filters!=null){
                String[] search=new String[5];

                search[0]=filters[0]!="0"?"producer_car.id="+filters[0]:"";
                search[1]= filters[1] != "0" ? "model_car.id=" + filters[1] : "";
                search[2]=filters[2]!=""?"car.color LIKE \'"+filters[2]+"\'":"";
                search[3]=filters[3]!=""?"car.price&lt;"+filters[3]:"";
                search[4] = filters[4] != "" ? "car.number_seats=" + filters[4] : "";
                var a=from f in search
                      where f!=""
                      select f;
                String filterAddition="";

                if(a.Count()&gt;0){
                    filterAddition=" WHERE ";
                    foreach ( var b in a){
                        filterAddition+=" "+b+" AND";
                    }
                    filterAddition=filterAddition.EndsWith("AND")?filterAddition.Substring(0,filterAddition.Length-3):filterAddition;

                }

               command+=filterAddition;

            }
            SqlCommand comm = new SqlCommand(command, conn);
            SqlDataReader r = null; 
            try
            {
                comm.Connection.Open();
                r =comm.ExecuteReader();
                gdvCar.DataSource = r;
                gdvCar.DataBind();
                r.Close();
            }
            catch (Exception exc)
            {
                throw (exc);
            }
            finally
            {


                conn.Close();
            }

        }

        private void StoreFilters()
        {
            filters = new String[5];
            filters[0] = ddlProducer.SelectedValue;
            filters[1] = ddlModel.SelectedValue;
            filters[2] = ddlColor.SelectedValue;
            filters[3] = txtStartPrice.Text;

            filters[4] = ddlNumber.SelectedValue;
            Session["1"] = filters;
        }

        private void RestoreFilters()
        {
            if (Session["1"] != null)
            {
                filters = (String[])Session["1"];
                ddlProducer.SelectedValue = filters[0];
                ddlProducer_Changed(null, null);
                ddlModel.SelectedValue = filters[1];
                ddlColor.SelectedValue = filters[2];
                txtStartPrice.Text = filters[3];

                ddlNumber.SelectedValue = filters[4];
            }

        }

        private void ReserveCar(String FirstName, String LastName, DateTime Start, DateTime End, String Visa, Int16 CarId)
        {
            hmsDataContext hms = new hmsDataContext();
            var a = from c in hms.cars
                    from rc in hms.rented_cars
                    where c.id == rc.id_car &amp;&amp; c.id == CarId
                    select new
                    {
                        start = rc.start,
                        end = rc.end
                    };

            Boolean free = false;
            if (a.Count() == 0)
            {
                free = true;
            }
            else if (a.Count() == 1)
            {
                if ((a.First().start &gt; End) || (a.First().end &lt; Start))
                    free = true;
            }
            else
            {
                if ((a.First().start &gt; End) || (a.First().end &lt; Start))
                    free = true;
                else if(!free)
                {
                    int n = a.Count();
                    for (int i = 0; (i &lt; n - 1) &amp;&amp; (!free); i++)
                    {
                        if (a.ElementAt(i).end &lt; Start &amp;&amp; a.ElementAt(i + 1).start &gt; End)
                            free = true;
                        i++;
                    }
                    if (!free)
                    {
                        if (a.ElementAt(n - 1).end &lt; Start)
                            free = true;
                    }
                }
            }

            if (free)
            {
                //insert
            }
            else
            {
                //label-nije slobodno za taj termin
            }
        }

        #endregion


    }
}
</code></pre>

<p>aspx</p>

<pre><code>&lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Cars.aspx.cs" Inherits="HMS.Cars"
    MasterPageFile="~/frame.Master" %&gt;

&lt;%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %&gt;

&lt;asp:Content ContentPlaceHolderID="content" ID="con" runat="server"&gt;
    &lt;link rel="StyleSheet" href="css/menu.css" type="text/css" media="all"&gt;
    &lt;asp:ScriptManager ID="sc" runat="server"&gt;
    &lt;/asp:ScriptManager&gt;
    &lt;div id="menu"&gt;
        &lt;ul class="glossymenu"&gt;
            &lt;li&gt;&lt;a href="Home.aspx"&gt;&lt;b&gt;Home&lt;/b&gt;&lt;/a&gt;&lt;/li&gt;
            &lt;li class="current"&gt;&lt;a href="Cars.aspx"&gt;&lt;b&gt;Cars&lt;/b&gt;&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="Boats.aspx"&gt;&lt;b&gt;Boats&lt;/b&gt;&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="Contact.aspx"&gt;&lt;b&gt;Contact&lt;/b&gt;&lt;/a&gt;&lt;/li&gt;
            &lt;li&gt;&lt;a href="Admin.aspx"&gt;&lt;b&gt;Admin&lt;/b&gt;&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;
    &lt;div&gt;
        &lt;div&gt;
            &lt;asp:UpdatePanel ID="upSearch" runat="server" UpdateMode="Conditional"&gt;
                &lt;ContentTemplate&gt;
                    &lt;div id="search"&gt;
                        &lt;fieldset&gt;
                            &lt;legend&gt;Advanced search&lt;/legend&gt;
                            &lt;table&gt;
                                &lt;tr&gt;
                                    &lt;td&gt;
                                        Proizvođač:&lt;asp:DropDownList ID="ddlProducer" runat="server" OnSelectedIndexChanged="ddlProducer_Changed"
                                            AutoPostBack="true"&gt;
                                        &lt;/asp:DropDownList&gt;
                                    &lt;/td&gt;
                                    &lt;td&gt;
                                        Model:&lt;asp:DropDownList ID="ddlModel" runat="server" Enabled="false"&gt;
                                        &lt;/asp:DropDownList&gt;
                                    &lt;/td&gt;
                                    &lt;td&gt;
                                        Boja:&lt;asp:DropDownList ID="ddlColor" runat="server"&gt;
                                            &lt;asp:ListItem Text="all" Value=""&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="White" Value="white"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="Green" Value="green"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="White" Value="white"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="Green" Value="green"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="White" Value="white"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="Green" Value="green"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="White" Value="white"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="Green" Value="green"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="White" Value="white"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="Green" Value="green"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="White" Value="white"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="Green" Value="green"&gt;&lt;/asp:ListItem&gt;
                                        &lt;/asp:DropDownList&gt;
                                    &lt;/td&gt;
                                    &lt;td&gt;
                                        Cena do:
                                        &lt;asp:TextBox ID="txtStartPrice" runat="server" MaxLength="10"&gt;&lt;/asp:TextBox&gt;
                                        din/dan
                                    &lt;/td&gt;
                                    &lt;td&gt;
                                        Number seats:&lt;asp:DropDownList ID="ddlNumber" runat="server"&gt;
                                            &lt;asp:ListItem Text="-- --" Value=""&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="1" Value="1"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="2" Value="2"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="3" Value="3"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="4" Value="4"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="5" Value="1"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="6" Value="2"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="7" Value="3"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="8" Value="4"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="9" Value="2"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="10" Value="3"&gt;&lt;/asp:ListItem&gt;
                                            &lt;asp:ListItem Text="11" Value="4"&gt;&lt;/asp:ListItem&gt;
                                        &lt;/asp:DropDownList&gt;
                                    &lt;/td&gt;
                                    &lt;td&gt;
                                        &lt;asp:ImageButton ID="imbSearch" runat="server" ImageUrl="images/icons/search.png"
                                            Width="32" Height="32" ToolTip="Search by choosen criterions" AlternateText="Search"
                                            OnClick="imbSearch_Click" /&gt;
                                    &lt;/td&gt;
                                &lt;/tr&gt;
                            &lt;/table&gt;
                        &lt;/fieldset&gt;
                    &lt;/div&gt;

                &lt;/ContentTemplate&gt;
            &lt;/asp:UpdatePanel&gt;
            &lt;br /&gt;
            &lt;br /&gt;
            &lt;div&gt;
                &lt;asp:UpdatePanel ID="upGrid" runat="server" UpdateMode="Always"&gt;
                    &lt;ContentTemplate&gt;
                        &lt;asp:GridView ID="gdvCar" runat="server"  OnRowCommand="gdvCar_RowCommand"
                            OnRowDataBound="gdvCar_DataBound"&gt;
                        &lt;/asp:GridView&gt;
                    &lt;/ContentTemplate&gt;
                &lt;/asp:UpdatePanel&gt;
            &lt;/div&gt;
            &lt;div&gt;
            &lt;asp:UpdatePanel ID="upTemp" runat="server"&gt;&lt;ContentTemplate&gt;
                &lt;asp:Panel ID="pnlReserve" runat="server" Visible="false" Width="400" Height="400"&gt;
                &lt;asp:UpdatePanel ID="upReserve" runat="server"&gt;
                &lt;ContentTemplate&gt;

                &lt;/ContentTemplate&gt;
                &lt;/asp:UpdatePanel&gt;
                &lt;/asp:Panel&gt;
                &lt;/ContentTemplate&gt;&lt;/asp:UpdatePanel&gt;
            &lt;/div&gt;

        &lt;/div&gt;
&lt;/asp:Content&gt;
</code></pre>
