我在DropDownList
的标头中有一个GridView
,我将其数据绑定在RowDataBound
并将其放在UpdatePanel
中。我想在选择后保留选定的值(回发)。怎么样?
这里我填写下拉列表
受保护的子gvStaffList_RowDataBound(sender As Object,e As System.Web.UI.WebControls.GridViewRowEventArgs)处理gvStaffList.RowDataBound
If e.Row.RowType = DataControlRowType.Header Then
' Fill the header dropdownlist from the datatable and displaying only the unique values (NOT from database directly)
' ============================= Supervisor name ======================================================
Dim ddlSupervisors As DropDownList = DirectCast(e.Row.FindControl("ddlSupervisors"), DropDownList)
For x As Integer = 0 To data.Rows.Count - 1
If ddlSupervisors.Items.FindByValue(data.Rows(x).Item("SuperId")) Is Nothing Then
ddlSupervisors.Items.Add(New ListItem(data.Rows(x).Item("SuperName"), data.Rows(x).Item("SuperId")))
End If
Next
ddlSupervisors.Items.Insert(0, New ListItem("All", "All"))
' ============================= Supervisor name ======================================================
Dim ddlPostTitle As DropDownList = DirectCast(e.Row.FindControl("ddlPostTitle"), DropDownList)
For x As Integer = 0 To data.Rows.Count - 1
If ddlPostTitle.Items.FindByValue(data.Rows(x).Item(1)) Is Nothing Then
ddlPostTitle.Items.Add(New ListItem(data.Rows(x).Item(1), data.Rows(x).Item(1)))
End If
Next
ddlPostTitle.Items.Insert(0, New ListItem("All", "All"))
答案 0 :(得分:0)
您可以在IndexChanged事件期间将其存储在会话中,然后将其拉回。
答案 1 :(得分:0)
你好这样使用会话:
Session["selecteditem"] = "your value";
c#上的; - )
答案 2 :(得分:0)
尝试在回发后再次重新填充下拉列表,然后在重新填写后再保留选定的下拉列表值。
尝试一下,如果有任何问题请告诉我