Add ASP.NET Controls Dynamically in GridView Cell on Checkbox SelectedIndexChanged Using UpdatePanel
<p>I have GridView. I want to add asp.net controls like textbox, dropdownlist etc dynamically on Gridview RowDataBound event. I have dropdownlist. When i select any item from dropdownlist, the gridview is filled in its SelectedIndexChanged event.
I add controls in GridView on RowDataBound event.
When I use UpdatePanel, Gridview donot fill controls. Without using UpdatePanel, it works. but i want it using UpdatePanel.
My gridview code is as below.</p>

<pre><code>&lt;asp:UpdatePanel ID="upSearchSPParameters" runat="server" UpdateMode="Conditional"
                        EnableViewState="true"&gt;
                        &lt;ContentTemplate&gt;
                            &lt;asp:GridView ID="grdSPParameters" runat="server" AllowPaging="false" AllowSorting="false"
                                CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
                                ShowHeader="false" ShowFooter="false" AutoGenerateColumns="False" DataKeyNames="iID"
                                EmptyDataText="" GridLines="None" EnableViewState="true"&gt;
                                &lt;Columns&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;ItemTemplate&gt;
                                            &lt;asp:Label ID="lblLabelParameter" runat="server" Text='&lt;%#Eval("cTag") %&gt;'&gt;&lt;/asp:Label&gt;
                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                    &lt;asp:TemplateField&gt;
                                        &lt;ItemTemplate&gt;

                                        &lt;/ItemTemplate&gt;
                                    &lt;/asp:TemplateField&gt;
                                &lt;/Columns&gt;
                            &lt;/asp:GridView&gt;
                        &lt;/ContentTemplate&gt;
                     &lt;Triggers&gt;
                            &lt;asp:AsyncPostBackTrigger ControlID="ddlSearchReportName" EventName="SelectedIndexChanged"  /&gt;
                        &lt;/Triggers&gt; 
                    &lt;/asp:UpdatePanel&gt;
</code></pre>

<p>.cs file code:</p>

<pre><code>Protected Sub grdSPParameters_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdSPParameters.RowDataBound
        Try
            If e.Row.RowType = DataControlRowType.DataRow Then
                Select Case e.Row.DataItem("cType").ToString.ToUpper
                    Case "TEXTBOX".ToUpper
                        Dim oTextbox As New TextBox
                        oTextbox.ID = "txtParam"
                        oTextbox.EnableViewState = True
                        e.Row.Cells(1).Controls.Add(oTextbox)
                    Case "COMBOBOX".ToUpper
                        Dim oDDL As New DropDownList
                        oDDL.ID = "ddlParam"

                        Dim oDs As New DataSet
                        oDs = oDAL.GetReportParameterQuery(e.Row.DataItem("cQuery").ToString)
                        oDDL.DataSource = oDs.Tables(0)
                        oDDL.DataTextField = "cName"
                        oDDL.DataValueField = "iID"
                        oDDL.DataBind()
                        e.Row.Cells(1).Controls.Add(oDDL)
                    Case "DATEPICKER".ToUpper
                        Dim oTxtDtPick As New TextBox
                        oTxtDtPick.ID = "txtParamPK"

                        Dim oSpan As New HtmlGenericControl
                        oSpan.InnerText = "(mm/dd/yyyy)"
                        oSpan.Attributes.Add("class", "")
                        oTxtDtPick.EnableViewState = True
                        oSpan.EnableViewState = True
                        e.Row.Cells(1).Controls.Add(oTxtDtPick)
                        e.Row.Cells(1).Controls.Add(oSpan)

                        Dim oTxt As New TextBox
                        oTxt = e.Row.FindControl(oTxtDtPick.ID)
                        oTxt.Attributes.Add("onclick", "cal1xx.select(document.forms[0]." + oTxt.ClientID + ",'" + oTxt.ClientID + "','MM/dd/yyyy'); return false;")

                    Case Else

                End Select
            End If
        Catch ex As Exception
            General.LogException(ex)
        End Try
    End Sub
</code></pre>

<p>My purpose is to dynamically create controls in gridview on gridview databind.</p>
