1

我有 GridView。我想在 Gridview RowDataBound 事件上动态添加 asp.net 控件,如文本框、下拉列表等。我有下拉列表。当我从下拉列表中选择任何项目时,gridview 将填充其 SelectedIndexChanged 事件。我在 RowDataBound 事件的 GridView 中添加控件。当我使用 UpdatePanel 时,Gridview 不会填充控件。不使用 UpdatePanel,它可以工作。但我希望它使用 UpdatePanel。我的gridview代码如下。

<asp:UpdatePanel ID="upSearchSPParameters" runat="server" UpdateMode="Conditional"
                        EnableViewState="true">
                        <ContentTemplate>
                            <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">
                                <Columns>
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <asp:Label ID="lblLabelParameter" runat="server" Text='<%#Eval("cTag") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <ItemTemplate>

                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:GridView>
                        </ContentTemplate>
                     <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="ddlSearchReportName" EventName="SelectedIndexChanged"  />
                        </Triggers> 
                    </asp:UpdatePanel>

.cs 文件代码:

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

我的目的是在 gridview 数据绑定上的 gridview 中动态创建控件。

4

0 回答 0