skip to Main Content

Why can’t I use the (input) I put in my (list view) in the C # code field?

<asp:ListView ID="ListV" runat="server">
    <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

enter image description here

2

Answers


  1. You want a server control there. Additionally, this control only exists as part of an item template, meaning there isn’t just one control named quantity2… there could be many, depending on the data source. Therefore referencing it just by name is not good enough. And speaking of data sources, depending on how you handle this the databinding may not have taken place yet at the time the Page_Load code runs, meaning the input control doesn’t exist at all.

    So the real question is: what do you want to do with this input?

    Login or Signup to reply.
  2. CodeBehind="~/ (Page Name) .aspx.cs"

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search