**为什么我无法访问我在视图列表中放入 Web 表单的内容,例如 C# 代码部分中的(输入)和(按钮)?**
**Why can't I access the things I put into the web form in the view list like (input)and(Button)inside the c# code section?**
为什么我无法访问我在视图列表中放入 Web 表单的内容,例如 C# 代码部分中的 (input) 和 (Button)?
<ItemTemplate runat="server">
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<tr class="text-center">
<td class="product-remove"></td>
<td class="image-prod">
<div class="">
<asp:Image ID="Image1" CssClass=" img" ImageUrl='<%# "../img/" + Eval("picture") %> ' runat="server" />
</div>
</td>
<td class="product-name"><%# Eval("namebook") %> </td>
<td class="price"><%# Eval("Price") %> </td>
<td class="quantity"><%# Eval("titel") %></td>
<td class="col-2">
<asp:Button ID="delete" CssClass="btn btn-outline-danger" CommandArgument='<%# Eval("id")%>' OnClick="delete_Click" runat="server" Text="حذف کالا" />
</td>
<td>
<input id="quantity2" runat="server" type="number" value="1" min="1" max="20" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
But on a page with the same code, I have access to the elements I put
in ListView.
试试这个:
Button btnDelete;
Label lbl2;
foreach (ListViewItem item in ListView1.Items)
{
lbl2 = (Label)item.FindControl("Label2");
btnDelete = (Button)item.FindControl("delete")
}
为什么我无法访问我在视图列表中放入 Web 表单的内容,例如 C# 代码部分中的 (input) 和 (Button)?
<ItemTemplate runat="server">
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<tr class="text-center">
<td class="product-remove"></td>
<td class="image-prod">
<div class="">
<asp:Image ID="Image1" CssClass=" img" ImageUrl='<%# "../img/" + Eval("picture") %> ' runat="server" />
</div>
</td>
<td class="product-name"><%# Eval("namebook") %> </td>
<td class="price"><%# Eval("Price") %> </td>
<td class="quantity"><%# Eval("titel") %></td>
<td class="col-2">
<asp:Button ID="delete" CssClass="btn btn-outline-danger" CommandArgument='<%# Eval("id")%>' OnClick="delete_Click" runat="server" Text="حذف کالا" />
</td>
<td>
<input id="quantity2" runat="server" type="number" value="1" min="1" max="20" />
</td>
</tr>
</ItemTemplate>
</asp:ListView>
But on a page with the same code, I have access to the elements I put in ListView.
试试这个:
Button btnDelete;
Label lbl2;
foreach (ListViewItem item in ListView1.Items)
{
lbl2 = (Label)item.FindControl("Label2");
btnDelete = (Button)item.FindControl("delete")
}