[SOLVED] **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?**

Issue

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 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> 

enter image description here

But on a page with the same code, I have access to the elements I put
in ListView.

enter image description here

Solution

Try this:

Button btnDelete;
Label lbl2;

    foreach (ListViewItem item in ListView1.Items)
            {
                lbl2 = (Label)item.FindControl("Label2");
                btnDelete = (Button)item.FindControl("delete")
               
            }

Answered By – duerzd696

Answer Checked By – David Goodson (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *