locked
code not working but also not giving any errors RRS feed

  • Question

  • User-766534054 posted
    <%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="CosCumparaturi.aspx.vb" Inherits="CosCumparaturi" %>
    
    <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" GridLines="None">
        <Columns>
            <asp:BoundField DataField="idcontinut" HeaderText="idcontinut" SortExpression="idcontinut" />
    <%--        <asp:BoundField DataField="idcomanda" HeaderText="idcomanda" SortExpression="idcomanda" />--%>
            <asp:BoundField DataField="denumireprodus" HeaderText="denumireprodus" SortExpression="denumireprodus" />
            <asp:ImageField DataImageUrlField="fotoprodus">
                <ControlStyle Height="100px" Width="100px" />
            </asp:ImageField>
            <asp:BoundField DataField="pretcomanda" HeaderText="pretcomanda" SortExpression="pretcomanda" />
            <asp:BoundField DataField="cantitate" HeaderText="cantitate" SortExpression="cantitate" />
            <asp:BoundField DataField="valoare" HeaderText="valoare" SortExpression="valoare" />
    <%--        <asp:BoundField DataField="adresaemail" HeaderText="adresaemail" SortExpression="adresaemail" />--%>
             <asp:TemplateField>
              <ItemTemplate>
                            <asp:Button ID="Button1" runat="server" Style="width:110px" Text="sterge" OnCommand="Button1_Command" CommandArgument='<%# Eval("IdContinut") %>' CssClass="buton" />
              </ItemTemplate>
    </asp:TemplateField>
             <asp:TemplateField>
              <ItemTemplate>
                            <asp:Button ID="Button2" runat="server" Style="width:110px" CssClass="buton" Text="modifica cantitatea" CommandName="Modificare" CommandArgument='<%# CType(Container, GridViewRow).RowIndex %>' />
    
              </ItemTemplate>
    </asp:TemplateField>
             <asp:TemplateField>
              <ItemTemplate>
              <asp:Label ID="Label1" runat="server" Text="introduceti noua cantitate"></asp:Label>
              <asp:TextBox ID="TextBox1" Style="width:10px" runat="server"></asp:TextBox>
              </ItemTemplate>
    </asp:TemplateField>
          
           
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Magazin_virtualConnectionString %>" SelectCommand="spcoscumparaturi" SelectCommandType="StoredProcedure" DeleteCommand="stergeprodus2" DeleteCommandType="StoredProcedure" UpdateCommand="actualizarecant2" UpdateCommandType="StoredProcedure">
        <DeleteParameters>
            <asp:Parameter Name="idcontinut" Type="Int32" />
        </DeleteParameters>
        <SelectParameters>
            <asp:SessionParameter Name="mail" SessionField="mail_introdus" Type="String" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="idcontinut" Type="Int32" />
            <asp:Parameter Name="cantitate" Type="Decimal" />
        </UpdateParameters>
    </asp:SqlDataSource>
         <table class="auto-style1">
            <tr>
                <td class="auto-style2">Valoare totala comanda:</td>
                <td class="auto-style3">
                    <asp:Label ID="lbltot" runat="server" ></asp:Label>
                </td>
                <td>
                    <asp:Button ID="Button1" runat="server" CssClass="auto-style4" Text="finalizeaza comanda" />
                </td>
            </tr>
        </table>
        <br />
        <asp:HyperLink ID="HyperLink15" runat="server" NavigateUrl="~/istoriccomenzi.aspx">Vizualizare istoric comenzi</asp:HyperLink>
    </asp:Content>
    
    
    
    Imports System.Data
    Imports System.Data.SqlClient
    Imports System.Configuration
    Partial Class CosCumparaturi
        Inherits System.Web.UI.Page
        Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
            If Not Page.IsPostBack Then
                GridView2.Columns(8).Visible = True
                If Session("mail_introdus") IsNot Nothing Then
                    'Dim conexiune As New SqlConnection
                    'conexiune.ConnectionString = "Data Source=ASUS\SQL123;Initial Catalog=Magazin_virtual;Integrated Security=True"
                    'conexiune.Open()
                    'Dim comanda As New SqlCommand
                    'comanda.Connection = conexiune
                    'comanda.CommandType = CommandType.StoredProcedure
                    'comanda.CommandText = "totalcomanda"
                    'comanda.Parameters.Add("@mail", SqlDbType.NVarChar)
                    'comanda.Parameters("@mail").Value = Session("mail_introdus")
                    'comanda.Parameters.Add("@totalcomanda", SqlDbType.Money).Direction = ParameterDirection.Output
                    'comanda.ExecuteNonQuery()
                    'conexiune.Close()
                    'Dim ttl As String = comanda.Parameters("@totalcomanda").Value.ToString()
                    'If ttl = Nothing Then
                    '    Response.Redirect("coscumparaturigol.aspx")
                    'Else
                    '    lbltot.Text = ttl
                    '    lbltot.Text = String.Format("{0:C}", Convert.ToDecimal(lbltot.Text))
                    'End If
                    calcul_total()
                Else
                    Response.Redirect("autentificare.aspx")
    
                End If
            End If
        End Sub
        Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Response.Redirect("finalizarecomanda.aspx")
        End Sub
        Protected Sub Button1_Command(sender As Object, e As CommandEventArgs)
            Dim conexiune As New SqlConnection
            conexiune.ConnectionString = "Data Source=ASUS\SQL123;Initial Catalog=Magazin_virtual;Integrated Security=True"
            conexiune.Open()
            Dim comandas As New SqlCommand
            comandas.Connection = conexiune
            comandas.CommandType = CommandType.StoredProcedure
            comandas.CommandText = "stergeprodus2"
            comandas.Parameters.Add("@idcontinut", SqlDbType.Int)
            comandas.Parameters("@idcontinut").Value = e.CommandArgument
            comandas.ExecuteNonQuery()
            conexiune.Close()
            GridView2.DataBind()
            calcul_total()
        End Sub
    
    
        Sub calcul_total()
            Dim conexiune As New SqlConnection
            conexiune.ConnectionString = "Data Source=ASUS\SQL123;Initial Catalog=Magazin_virtual;Integrated Security=True"
            conexiune.Open()
            Dim comanda As New SqlCommand
            comanda.Connection = conexiune
            comanda.CommandType = CommandType.StoredProcedure
            comanda.CommandText = "totalcomanda"
            comanda.Parameters.Add("@mail", SqlDbType.NVarChar)
            comanda.Parameters("@mail").Value = Session("mail_introdus")
            comanda.Parameters.Add("@totalcomanda", SqlDbType.Money).Direction = ParameterDirection.Output
            comanda.ExecuteNonQuery()
            conexiune.Close()
            Dim ttl As String = comanda.Parameters("@totalcomanda").Value.ToString()
            If ttl = Nothing Then
                Response.Redirect("coscumparaturigol.aspx")
            Else
                lbltot.Text = ttl
                lbltot.Text = String.Format("{0:C}", Convert.ToDecimal(lbltot.Text))
            End If
        End Sub
        'Protected Sub Button2_Command(sender As Object, e As CommandEventArgs)
        '    GridView2.Columns(8).Visible = True
        '    Dim conexiune As New SqlConnection
        '    conexiune.ConnectionString = "Data Source=ASUS\SQL123;Initial Catalog=Magazin_virtual;Integrated Security=True"
        '    conexiune.Open()
        '    Dim comandaa As New SqlCommand
        '    comandaa.Connection = conexiune
        '    comandaa.CommandType = CommandType.StoredProcedure
        '    comandaa.CommandText = "actualizarecant2"
        '    comandaa.Parameters.Add("@idcontinut", SqlDbType.Int)
        '    comandaa.Parameters("@idcontinut").Value = e.CommandArgument
        '    comandaa.Parameters.Add("@cantitate", SqlDbType.Decimal)
        '    Dim index As Integer = Convert.ToInt32(e.CommandArgument)
        '    Dim mySelectedRow As GridViewRow = GridView2.Rows(index)
        '    Dim MyText As String = CType(mySelectedRow.FindControl("textbox1"), TextBox).Text
        '    comandaa.Parameters("@cantitate").Value =
        '    comandaa.ExecuteNonQuery()
        '    conexiune.Close()
        '    GridView2.DataBind()
        '    calcul_total()
        'End Sub
        Protected Sub GridView2_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
            If (e.CommandName = "Modificare") Then
                'first find the button that got clicked
                Dim index As Integer = Convert.ToInt32(e.CommandArgument)
                'find the row of the button
                Dim row As GridViewRow = GridView2.Rows(index)
                'now as the UserName is in the BoundField, access it using the cell index.
             Dim cantitate As String = CType(row.FindControl("Textbox1"), TextBox).Text
                GridView2.Columns(8).Visible = True
                Dim conexiune As New SqlConnection
                conexiune.ConnectionString = "Data Source=ASUS\SQL123;Initial Catalog=Magazin_virtual;Integrated Security=True"
                conexiune.Open()
                Dim comandaa As New SqlCommand
                comandaa.Connection = conexiune
                comandaa.CommandType = CommandType.StoredProcedure
                comandaa.CommandText = "actualizarecant2"
                comandaa.Parameters.Add("@idcontinut", SqlDbType.Int)
                comandaa.Parameters("@idcontinut").Value = row.Cells(0).Text
                comandaa.Parameters.Add("@cantitate", SqlDbType.Decimal)
                comandaa.Parameters("@cantitate").Value = cantitate
                comandaa.ExecuteNonQuery()
                conexiune.Close()
                GridView2.DataBind()
                calcul_total()
            End If
    
        End Sub
    
    End Class


    Hello!

    For my bachelor thesis I have to do an webshop and I've gotten to the part where I have to update quantity in the shopping cart. My shopping cart is based on a sql procedure, not on a table, therefore I cannot use update or delete commands. So I have created buttons inside template fields for each one of these commands, I've got delete command working, but I cannot get update command running, when I press the button for update command it loads for a while, but then nothing changes, and I don't get any errors on my code either. I am going crazy here, because it needs to be done by monday. Here is my code, any suggestions would be perfect, thank you!!! ps: some of the commented code was done by my teacher, and some was copied from the internet on the intent of solving this issue.

    Saturday, June 23, 2018 6:48 PM

Answers

  • User753101303 posted

    Hi,

    For now it seems you don't have anything to bind an even to the event hanling code and so you would need to add  Handles GridView2.RowCommand as you have done already for other events?

    You have tools such as https://docs.microsoft.com/en-us/visualstudio/debugger/debugger-feature-tour

    It would allow to check if your code is even really called. It is IMO best to always see what happens EXACTLY (for example is my code even called ?) rather than starting right away by reading your code.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 25, 2018 7:36 AM

All replies

  • User753101303 posted

    Hi,

    For now it seems you don't have anything to bind an even to the event hanling code and so you would need to add  Handles GridView2.RowCommand as you have done already for other events?

    You have tools such as https://docs.microsoft.com/en-us/visualstudio/debugger/debugger-feature-tour

    It would allow to check if your code is even really called. It is IMO best to always see what happens EXACTLY (for example is my code even called ?) rather than starting right away by reading your code.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, June 25, 2018 7:36 AM
  • User-766534054 posted

    It worked!

    I wasn't even looking for the problem there. Thanks a lot, you saved me. Have a nice day!

    Monday, June 25, 2018 8:50 AM