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?
<ItemTemplate runat="server">
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
<tr >
<td ></td>
<td >
<div >
<asp:Image ID="Image1" CssClass=" img" ImageUrl='<%# "../img/" Eval("picture") %> ' runat="server" />
</div>
</td>
<td ><%# Eval("namebook") %> </td>
<td ><%# Eval("Price") %> </td>
<td ><%# Eval("titel") %></td>
<td >
<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.
CodePudding user response:
Try this:
Button btnDelete;
Label lbl2;
foreach (ListViewItem item in ListView1.Items)
{
lbl2 = (Label)item.FindControl("Label2");
btnDelete = (Button)item.FindControl("delete")
}