Home > Software engineering >  Unusable elements inside the (list view ) asp.net
Unusable elements inside the (list view ) asp.net

Time:02-24

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

enter image description here

enter image description here

CodePudding user response:

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?

CodePudding user response:

CodeBehind="~/ (Page Name) .aspx.cs"

  • Related