1

DropDownList在 a 的标头中有 a GridView,我将其数据绑定在 中RowDataBound并将其放在UpdatePanel. 我想在 selection(postback) 之后保留选定的值。如何 ?

在这里我填写下拉列表

Protected Sub 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"))
4

3 回答 3

0

您可以在 IndexChanged 事件期间将其存储在会话中,然后将其拉回。

于 2012-07-29T08:30:49.930 回答
0

你好使用这样的会话:

Session["selecteditem"] = "your value";

在 c# 上;-)

于 2012-07-29T08:32:42.947 回答
0

尝试在回发后再次填充您的下拉列表,然后您可以在再次填充后保留下拉列表的选定值。

尝试一下,如果有任何问题,请告诉我

于 2012-07-29T08:36:09.297 回答