[SOLVED] How to store information in the view list in the database


How can I save rows created in the list view in my database? How can I access the values ​​in the (list view)? How to save the values ​​created in the view list to the database?

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

            <td class="product-name"><%# Eval("namebook") %> </td>

                <td id="t_Plural" runat="server" 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="حذف کالا" />


                <%--                                            <input id="quantity2" runat="server" type="number" AutoPostBack="true" oninput="lod_gheymat" onserverclick="lod_gheymat" value="" min="1" max="20" />--%>
                <asp:TextBox ID="quantity2" runat="server" CssClass="input-wrap" AutoPostBack="true" OnTextChanged="lod_gheymat" Text="1" min="1" max="20"></asp:TextBox>

            <td >
                <div class="row">
               <asp:Label ID="lbl_Plural" runat="server" Text="0"></asp:Label>&nbsp;&nbsp;&nbsp;&nbsp; <span class="row"> تومان</span>


enter image description here


protected void savetodatabase_Click(object sender, EventArgs e)

    System.Web.UI.HtmlControls.HtmlGenericControl Labelid;
    TextBox quantity2;
    foreach (ListViewItem rRow in ListView1.Items)
        itemlist iteml = new itemlist();
        quantity2 = (TextBox)rRow.FindControl("quantity2");
        Labelid = (System.Web.UI.HtmlControls.HtmlGenericControl)rRow.FindControl("Labelid");
        iteml.quantity = quantity2.Text;
        iteml.bookid = Convert.ToInt32(Labelid.InnerText) ;
        iteml.Date = DateTime.Now;
        iteml.userid =  Convert.ToInt32(Session["userid"].ToString()) ;
        DatabaseContext context = new DatabaseContext();




Answered By – Stephen sf

Answer Checked By – Senaida (BugsFixing Volunteer)

Leave a Reply

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