85 messaggi dal 04 marzo 2012
Salve,
scusate la domanda da principiante ma mi sto perdendo in un bicchier d'acqua.
ho una semplice form dove c'è una gridview, selezionando un record accedo una un'altra form dove visualizzo e ho la possibilità di modificare i campi del record.
Quest'ultima form contiene un update panel e all'interno una table con i vari campi, il mio problema sta che se modifico un campo (es. da pippo lo faccio diventare pluto) quando clicck sul buttom "salva" a livello di codice mi trovo ancora il vecchio valore e non il nuovo e pertanto non riesco ad aggiornare il db.
Cosa sbaglio o cosa mi sfugge?
Tenete presente che la forma si basa su una master.page, ringrazio anticipatamente.

<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master" CodeBehind="ProcedureGestione.aspx.vb" Inherits="HTSToolsWeb.ProcedureGestione" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxToolkit" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">


<div class="DivComandi">
<asp:Table ID="tComandi" runat="server" >
<asp:TableRow>
<asp:TableCell>
<asp:ImageButton ID="bSalva" runat="server" ImageUrl="~/Images/IC_Salva.png" Width="30" Height="30" ToolTip="Salva" />
</asp:TableCell>
<asp:TableCell>

</asp:TableCell>
<asp:TableCell>
<asp:ImageButton ID="bAnnulla" runat="server" ImageUrl="~/Images/IC_Annulla.png" Width="30" Height="30" ToolTip="Annulla" />
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</div>

<div style="background-color: #EFEFEF">
<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
</asp:ScriptManagerProxy>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

<ContentTemplate>
<asp:Table ID="Table1" runat="server" Width="100%">
<asp:TableRow>
<asp:TableCell Width="33%">
<asp:Label ID="Label1" runat="server" Text="Codice"></asp:Label> <br />
<asp:TextBox ID="txtCodice" runat="server" ></asp:TextBox>
</asp:TableCell>

<asp:TableCell Width="33%" >
</asp:TableCell>

<asp:TableCell Width="33%">
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="2">
<asp:Label ID="Label2" runat="server" Text="Descrizione"></asp:Label> <br />
<asp:TextBox ID="txtDescrizione" runat="server" Width="550" ></asp:TextBox>
</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell>
<asp:Label ID="Label3" runat="server" Text="Revisione"></asp:Label> <br />
<asp:TextBox ID="txtRevisione" runat="server" ></asp:TextBox>
</asp:TableCell>

<asp:TableCell>
<asp:Label ID="Label4" runat="server" Text="Data Emissione"></asp:Label> <br />
<asp:TextBox ID="txtDataEmissione" runat="server"></asp:TextBox>
<ajaxToolkit:CalendarExtender ID="txtDataEmissione_CalendarExtender"
runat="server" BehaviorID="txtDataEmissione_CalendarExtender"
TargetControlID="txtDataEmissione">
</ajaxToolkit:CalendarExtender>

</asp:TableCell>
</asp:TableRow>

<asp:TableRow>
<asp:TableCell>
<asp:Label ID="Label5" runat="server" Text="Formato"></asp:Label> <br />
<asp:DropDownList ID="txtFormato" runat="server" DataSourceID="SqlDataFormato"
DataTextField="Formato" DataValueField="IDFormato" >
</asp:DropDownList>

<asp:SqlDataSource ID="SqlDataFormato" runat="server"
ConnectionString="<%$ ConnectionStrings:HTS_GestioneConnectionString %>"
SelectCommand="SELECT * FROM [Q_FormatoDocumenti] ORDER BY [Formato]">
</asp:SqlDataSource>
</asp:TableCell>
</asp:Table>
</ContentTemplate>
</asp:UpdatePanel>
</div>

<asp:SqlDataSource ID="SqlDataProcedure" runat="server"
ConnectionString="<%$ ConnectionStrings:HTS_GestioneConnectionString %>"
SelectCommand="SELECT [Codice], [Descrizione], [Revisione], [DataEmissione], [Link] FROM [Q_Procedure]">
</asp:SqlDataSource>

</asp:Content>
944 messaggi dal 11 febbraio 2013
Forse non ho capito ma non vedo il comando Update nel SqlDataSource
85 messaggi dal 04 marzo 2012
L'update lo faccio a livello di VB quando schiaccio sul tasto "Salva" di seguito il codice

Protected Sub bSalva_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bSalva.Click
' Effettuo i controlli
If Me.txtCodice.Text = "" Then
PopupErrori("Campo 'Codice' Obbligatorio!", "Inserire un codice.")
Me.txtCodice.Focus()
Exit Sub
End If

If Me.txtDescrizione.Text = "" Then
PopupErrori("Campo 'Descrizione' Obbligatoria!", "Inserire una descrizione.")
Me.txtDescrizione.Focus()
Exit Sub
End If

If Me.txtRevisione.Text = "" Then
PopupErrori("Campo 'Revisione' Obbligatorio!", "Inserire la revisione.")
Me.txtRevisione.Focus()
Exit Sub
End If

If Me.txtDataEmissione.Text = "" Then
PopupErrori("Campo 'Data Emissione' Obbligatoria!", "Inserire la data emissione.")
Me.txtDataEmissione.Focus()
Exit Sub
End If


' NUOVO
If Session.Item("Stato") = "Inserimento" Then
Try
Dim sDataEmissione As String
sDataEmissione = Mid(CStr(Me.txtDataEmissione.Text), 7, 4) & "-" & Mid(CStr(Me.txtDataEmissione.Text), 4, 2) & "-" & Mid(CStr(Me.txtDataEmissione.Text), 1, 2)

Query = "INSERT INTO Q_Procedure (Codice, Descrizione, Revisione, DataEmissione, Formato, DurataCons, Note, Link, TipoDoc, IDArea)"
Query = Query & " VALUES('" & txtCodice.Text & "',' " & txtDescrizione.Text & "', " & txtRevisione.Text & ",'" & sDataEmissione & "', '" & txtFormato.Text & "', '" & txtDurataCons.Text & "', '"
Query = Query & txtNote.Text & "', '" & txtLink.Text & "', '1-PRO', " & txtArea.Text & ")"


Me.SqlDataProcedure.InsertCommand = Query
Me.SqlDataProcedure.Insert()

' REINIZIALIZZO TUTTO
Session.Item("Stato") = ""

Session.Item("RecordSelezionato") = 0

Response.Redirect("procedureView.aspx")

Catch ex As Exception
ClsFileLog.ScriviLog(ex.Message, Session.Item("User"))
End Try
Else 'MODIFICA

Try
Dim sDataEmissione As String
sDataEmissione = Mid(CStr(Me.txtDataEmissione.Text), 7, 4) & "-" & Mid(CStr(Me.txtDataEmissione.Text), 4, 2) & "-" & Mid(CStr(Me.txtDataEmissione.Text), 1, 2)
Dim a As Integer
a = txtRevisione.Text

Query = "UPDATE Q_Procedure SET Codice ='" & Me.txtCodice.Text
Query = Query & "', Descrizione ='" & Me.txtDescrizione.Text & "', Revisione = " & Me.txtRevisione.Text & ", DataEmissione ='" & sDataEmissione & "', Formato ='" & txtFormato.SelectedValue & "', DurataCons ='" & txtDurataCons.SelectedValue
Query = Query & "', Note ='" & Me.txtNote.Text & "', Link ='" & Me.txtLink.Text & "', IDArea =" & Me.txtArea.SelectedValue
Query = Query & " FROM Q_Procedure WHERE IDProcedura =" & Session.Item("RecordSelezionato")

SqlDataProcedure.UpdateCommand = Query
SqlDataProcedure.Update()


Session.Item("RecordSelezionato") = 0

Response.Redirect("procedureView.aspx")


Catch ex As Exception
ClsFileLog.ScriviLog(ex.Message, Session.Item("User"))
End Try
End If
944 messaggi dal 11 febbraio 2013
ho provato a incollare il codice ma ho errori nel markup
ma dice

il contenuto in formato letterale non è consentito in un TableCellCollection

E nel codice del bottone ho 56 errori

Puoi postare il codice ho fare un progetto di esempio ?
Crea un db allegato con le tabelle che servono

Sicuramente qualcuno oltre me gli darà un'occhiata
85 messaggi dal 04 marzo 2012
Mentre stavo preparando un progetto di esempio, mi è venuto il flash.

Mi mancava nel load della pagina il controllo del not page.ispostback e pertanto eseguivo sempre il ricarico dei dati vecchi.

Ringrazio comunque per l'aiuto.

Torna al forum | Feed RSS

ASPItalia.com non è responsabile per il contenuto dei messaggi presenti su questo servizio, non avendo nessun controllo sui messaggi postati nei propri forum, che rappresentano l'espressione del pensiero degli autori.