我有GridView。我想在Gridview RowDataBound事件上动态添加像textbox,dropdownlist等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 databind上的gridview中动态创建控件。