我的程序中的更新面板中有一个asp下拉列表。 OnSelectedIndexChanged事件的功能正常工作,但问题是回帖后看不到下拉列表。以下是我的代码。
<asp:UpdatePanel ID="updatePanel1" runat="server">
<ContentTemplate>
<div class="row cancel-paddings cancel-margins">
<div class="field">
<asp:DropDownList ID="ddlDropdownSub1" EnableViewState="true" Visible="true" runat="server" class="dropdown" OnSelectedIndexChanged="OnSelectedIndex_dropdownSub1" AutoPostBack="true"></asp:DropDownList>
</div>
</div>
<div class="card-content">
<div class="listview is-selectable custom-scroll-one" id="task-listview" data-tmpl="task-tmpl" data-dataset="demoTasks" tabindex="-1" role="listbox" aria-label="Tasks">
<ul role="presentation">
<asp:GridView ID="gvCaseCards" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField >
<ItemTemplate>
<li aria-posinset="1" aria-setsize="12" tabindex="0" class="centered-block" aria-selected="true">
<asp:Label CssClass="listview-subheading" ID="lblCaseIdCaseCard" runat="server" Text=''></asp:Label><br />
<asp:Label CssClass="listview-heading wrap-text" ID="lblDescCaseCard" runat="server" Text=''></asp:Label><br />
<asp:Label CssClass="listview-subheading" ID="lblDueCaseCard" runat="server" Text=''></asp:Label><br /><br />
</li>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ul>
</div>
</div>
</ContentTemplate>
</asp:UpdatePanel>
在我的OnSelectedIndex_dropdownSub1函数中,我可以动态地获取gridview的值。我的页面加载方法如下。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Me.BindDataToDropDown1() 'fill data to dropdown
Me.BindDataToGridview() 'bind data to grid view
End If
End Sub
以下是OnSelectedIndex_dropdownSub1事件
Protected Sub OnSelectedIndex_dropdownSub1(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlDropdownSub1.SelectedIndexChanged
Me.BindDataToGridview()
End Sub
以下是我的binddatatodropdown函数
Public Function BindDataToDropDown1()
Dim ds As New DataSet
Dim alUtil As New ALUtility
Dim connString As String = AppSettings("conString")
Using cnn As New SqlConnection(connString)
cnn.Open()
Using dad As New SqlDataAdapter("SELECT * FROM product", cnn)
dad.Fill(ds)
End Using
cnn.Close()
End Using
ddlDropdownSub1.DataSource = ds
ddlDropdownSub1.DataTextField = "product_name"
ddlDropdownSub1.DataValueField = "product_id"
ddlDropdownSub1.DataBind()
End Function
BindDataToGrid函数如下,
Public Function BindDataToGridview()
Dim ds As New DataSet
Dim alUtil As New ALUtility
Dim connString As String = AppSettings("conString")
Dim product_id As Integer = Convert.ToInt32(ddlDropdownSub1.SelectedValue)
Using cnn As New SqlConnection(connString)
cnn.Open()
Using dad As New SqlDataAdapter(" Select * from Product Where product_id = " + product_id.ToString(), cnn)
dad.Fill(ds)
End Using
cnn.Close()
End Using
gvCaseCards.DataSource = ds
gvCaseCards.DataBind()
End Function
所有功能都正常工作,但回发后下拉消失。
任何人都可以帮我解决这个问题。
答案 0 :(得分:1)
据我所见,更新面板应该有一些更改。我一般都讨厌更新面板,并认为你应该总是尝试使用自己的AJAX代码。
首先,我认为您可以将Gridview
包装在<ContentTemplate>
标记中,因为这只是正在更新的控件。
然后你需要添加一个触发器,例如:
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlDropdownSub1" EventName="SelectedIndexChanged" />
</Triggers>
这超出了<ContentTemplate>
标签。我认为您还应该在UpdatePanel控件上添加UpdateMode="Conditional"
。