我对网格视图中的下拉列表有问题,它不会触发已更改的选择索引。当行数据绑定时,我绑定下拉列表的数据。但是当我选择数据时,它不会触发改变的选择索引。硬件编码项目列表的另一个下拉列表触发了选择索引的更改。关于这个问题的任何想法,请帮助。下面是代码背后和前端代码。
<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>
受保护的子Page_Load(ByVal sender As Object,ByVal e As System.EventArgs)处理Me.Load
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
答案 0 :(得分:0)
为什么在仅绑定If me.IsPostBack
时,在RowDataBound中添加了If Not IsPostBack
部分?
通常,在aspx标记中添加OnSelectedIndexChanged="ddlPrice_SelectedIndexChanged"
就足够了。但是你可以尝试在每个PostBack上的RowCreated中添加处理程序:
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