开发者

dropdownlist in gridview not fire select index changed

i have problem for the drop down list in the grid view, it not fire the select index changed. I bind the data for the drop down list when the row databound. But when i select the data, it not fire the select index changed. Another drop down list which hard code the item list fired the select index changed. Any idea on this issue, please help. Below is the code behind and the front end code.

                <ItemTemplate>
                    <asp:DropDownList ID="ddlItem" runat="server" Width="80%" AutoPostBack="true" OnSelectedIndexChanged="ddlPrice_SelectedIndexChanged"></asp:DropDownList>
                </ItemTemplate>



                <ItemTemplate>
                    <asp:DropDownList runat="server" ID="ddl" AutoPostBack="true" OnSelectedIndexChanged="ddl_SelectedIndexChanged">
                        <asp:ListItem Text="Compliant" Value="0" /> 
                                <asp:ListItem Text="Other Than Serious" Value="1" />
                                <asp:ListItem Text="Serious" Value="2" />
                                <asp:ListItem Text="Critical" Value="3" />

                    </asp:DropDownList>
                </ItemTemplate>

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load开发者_C百科

    Dim oCategoryDetails As New CategoryDetails

    If Not IsPostBack Then
        gdCat.DataSource = oCat.Read
        gdCat.DataBind()
    End If

End Sub

 Dim ddl As DropDownList
        ddl = DirectCast(e.Row.FindControl("ddlItem"), DropDownList)
        If Not ddl Is Nothing Then
            If oDS.Tables.Item(0).Rows.Count > 0 Then
                ddl.DataSource = oDS
                ddl.DataTextField = "ItemName"
                ddl.DataValueField = "ItemPrice"
                ddl.DataBind()
            Else
                ddl.Visible = False
            End If

        End If

        If Me.IsPostBack Then

            If e.Row.RowType = DataControlRowType.DataRow Then
                AddHandler ddl.SelectedIndexChanged, AddressOf ddlPrice_SelectedIndexChanged
            End If
        End If

End Sub


Why do you have added the part with If me.IsPostBack in RowDataBound when you only bind it If Not IsPostBack? Normally it should suffice to add OnSelectedIndexChanged="ddlPrice_SelectedIndexChanged" in the aspx markup. But you can try to add the handler in RowCreated on every PostBack:

Private Sub gdCat_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gdCat.RowCreated
    Select Case e.Row.RowType
        Case DataControlRowType.DataRow
            Dim ddlItem as DropDownList = DirectCast(e.Row.FindControl("ddlItem"),DropDownList)
            AddHandler ddlItem.SelectedIndexChanged, AddressOf ddlPrice_SelectedIndexChanged
    End Select
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜