我已经在整个网络上寻找类似的情况并且不能,请帮助我这件事让我疯了。
好的我要做的是在这些内部嵌套ListView和按钮,后面的代码无法看到嵌套listview中单击的按钮,例如。我有很多listview组需要留下来。如果我做1 listview父(按钮可以看到和工作)。它的父母 - >孩子 - >孩子(这里的按钮无法看到)这就是问题发生的地方。
所有数据都是正确的,列表视图分组都只是那个该死的按钮。
一些ASP代码提前为缩进道歉。
<asp:ListView ID="lvSOLGrpDelAdd" runat="server" ItemPlaceholderID="plcSOLGrpAdd">
<LayoutTemplate>
<table class="tblDespPackSOL">
<tr class="tblDespPackSOLH">
<td>O/N/L</td>
<td>Qty</td>
<td>Code</td>
<td>Description 1</td>
<td>Description 2</td>
<td>Unit Cost</td>
<td>Total</td>
<td>Qty Desp</td>
<td>Allocate</td>
</tr>
<asp:PlaceHolder ID="plcSOLGrpAdd" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr class="tblDespPackSOLAdd">
<td colspan="9"><%# Eval("Name") %>, <%# Eval("A1")%>, <%# Eval("A2")%>, <%# Eval("TownCity")%>, <%# Eval("CountyState")%>,<%# Eval("Country")%>, <%# Eval("PostCodeZip")%></td>
</tr>
<asp:ListView runat="server" ID="lvSOLGrpDelMeth" OnItemDataBound="lvSOLGrpDelMeth_RowDataBound">
<ItemTemplate>
<tr class="tblDespPackSOLDelMeth">
<td colspan="9">DELIVERY METHOD -->> <%# Eval("DescDelivMethod") %></td>
</tr>
<asp:ListView runat="server" ID="lvSOL" DataKeyNames="SalesOrderLine" OnItemDataBound="lvSOL_RowDataBound">
<ItemTemplate>
<tr id="trSOL" runat="server" class="tblDespPackSOLNorm">
<td>
<asp:HiddenField ID="hdnSOL" runat="server" Value='<%# Eval("SalesOrderLine") %>' />
<%# Eval("SalesOrderLine") %></td>
<td><%# Eval("Qty") %></td>
<td><%# Eval("Code") %></td>
<td><%# Eval("Desc1") %></td>
<td><%# Eval("Desc2") %></td>
<td><%# Eval("Symbol") %><%# Eval("CombUnitPrice") %></td>
<td><%# Eval("Symbol")%><%# Eval("Total") %></td>
<td><asp:DropDownList ID="lstQtyAvail" runat="server" CssClass="FTxtLst" AutoPostBack="true" Width="40px" /></td>
<td>
<asp:Button ID="btnAllocateLine" runat="server" CssClass="FBtn" Text="Allocate" CommandName="Click" CommandArgument='<%# Eval("SalesOrderLine") %>' OnClick="btnAllocateLine_Click" /></td>
</tr>
</ItemTemplate>
</asp:ListView>
</ItemTemplate>
</asp:ListView>
</ItemTemplate>
</asp:ListView>
以下是
背后的一些vb代码Protected Sub btnAllocateLine_Click(sender As Object, e As EventArgs)
MsgBox("If this pops up its tells me it works and it is not at all")
'If I try Handles btnAllocateLine.Click its tells me I need With Events
End Sub
Protected Sub Packing_Load(sender As Object, e As EventArgs) Handles Me.Load
FuncUsers_Get()
hdnIDSO.Value = tblUsers.IDOrder
hdnIDUser.Value = tblUsers.ID
lvSOLGrpDelAdd.DataSource = tblDespatchA.DespatchPackSOLGrpDelAdd_Get(IDSO:=hdnIDSO.Value)
lvSOLGrpDelAdd.DataBind()
End Sub
Protected Sub lvSOLGrpDelAdd_RowDataBound(sender As Object, e As ListViewItemEventArgs) Handles lvSOLGrpDelAdd.ItemDataBound
Dim lvSOLGrpDelMeth As ListView = DirectCast(e.Item.FindControl("lvSOLGrpDelMeth"), ListView)
lvSOLGrpDelMeth.DataSource = tblDespatchA.DespatchPackSOLGrpDelMeth_Get(IDSO:=hdnIDSO.Value, IDGrpDelAdd:=DataBinder.Eval(e.Item.DataItem, "IDGrpDelAdd"))
lvSOLGrpDelMeth.DataBind()
End Sub
Protected Sub lvSOLGrpDelMeth_RowDataBound(sender As Object, e As ListViewItemEventArgs)
Dim lvSOL As ListView = DirectCast(e.Item.FindControl("lvSOL"), ListView)
lvSOL.DataSource = tblDespatchA.DespatchPackSOL_Get(IDSO:=hdnIDSO.Value, IDGrpDelAdd:=DataBinder.Eval(e.Item.DataItem, "IDGrpDelAdd").ToString, IDGrpDelMeth:=DataBinder.Eval(e.Item.DataItem, "IDGrpDelMeth").ToString)
lvSOL.DataBind()
End Sub
答案 0 :(得分:1)
尝试使用lvSOL_RowDataBound事件处理程序中的AddHandler连接事件:
Protected Sub lvSOL_RowDataBound(sender As Object, e As ListViewItemEventArgs)
Dim btnAllocateLine As Button = CType(e.Item.FindControl("btnAllocateLine"), Button)
AddHandler btnAllocateLine.Click, AddressOf btnAllocateLine_Click
End Sub
答案 1 :(得分:0)
为了上帝的缘故。我自己修好了。对于任何有类似问题的人来说,答案就是滚筒!回发问题。
我的加载代码绑定数据,但是每次单击任何按钮都会导致回发,即使我将AutoPostBack =“False”,还有ChildrenAsTriggers =“false”和UpdateMode =“Conditional”,它仍然会回发。因此,每次单击一个按钮时,都会重新绑定并在按钮事件被触发时为所有子项构建父Listview。
简单修复只是确保页面加载事件仅在页面加载而不是回发时触发。所以下面添加IsPostBack = False,下面的工作示例。
Protected Sub Packing_Load(sender As Object, e As EventArgs) Handles Me.Load
FuncUsers_Get()
hdnIDSO.Value = tblUsers.IDOrder
hdnIDUser.Value = tblUsers.ID
If IsPostBack = False Then
lvSOLGrpDelAdd.DataSource = tblDespatchA.DespatchPackSOLGrpDelAdd_Get(IDSO:=hdnIDSO.Value)
lvSOLGrpDelAdd.DataBind()
End If
End Sub