By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,990 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,990 IT Pros & Developers. It's quick & easy.

like avoiding to always insert the same elements

P: n/a
I am making the pages asp of one library on-linens with visual study 2003. I
have created the datagrid, the subroutine UpdateCommand. .now I want to
avoid to always insert the same element. .someone says me like making? I
would have to make a IF. .but like? In order to help to understand you, I
put you the code vb and that asp of mine web form!

Imports System.Data.SqlClient

Public Class WebForm9

Inherits System.Web.UI.Page

Dim conDatabase_BIBLIOTECA As SqlConnection

Dim cmdSql As SqlCommand

Protected WithEvents dgrdLIBRI As System.Web.UI.WebControls.DataGrid

Dim strSql As String

#Region " Codice generato da Progettazione Web Form "

'Chiamata richiesta da Progettazione Web Form.

<System.Diagnostics.DebuggerStepThrough()Private Sub InitializeComponent()

End Sub

'NOTA: la seguente dichiarazione richiesta da Progettazione Web Form.

'Non spostarla o rimuoverla.

Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init

'CODEGEN: questa chiamata al metodo richiesta da Progettazione Web Form.

'Non modificarla nell'editor del codice.

InitializeComponent()

End Sub

#End Region

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

'Inserire qui il codice utente necessario per inizializzare la pagina

conDatabase_BIBLIOTECA = New SqlConnection("Server=.;database=Database
BIBLIOTECA;Integrated Security=SSPP;Trusted_Connection=Yes")

If Not IsPostBack Then

BindDataGrid()

End If

End Sub

Sub BindDataGrid()

cmdSql = New SqlCommand("SELECT * FROM LIBRI", conDatabase_BIBLIOTECA)

conDatabase_BIBLIOTECA.Open()

dgrdLIBRI.DataSource = cmdSql.ExecuteReader

dgrdLIBRI.DataBind()

conDatabase_BIBLIOTECA.Close()

End Sub

Sub dgrdLIBRI_EditCommand(ByVal source As Object, ByVal e As
DataGridCommandEventArgs)

dgrdLIBRI.EditItemIndex = e.Item.ItemIndex

BindDataGrid()

End Sub

Sub dgrdLIBRI_UpdateCommand(ByVal source As Object, ByVal e As
DataGridCommandEventArgs)

Dim intId_libri As Integer

Dim txtCodice_Rfid As TextBox

Dim TxtTitolo_del_libro As TextBox

Dim strCodice_Rfid As String

Dim strTitolo_del_libro As String

intId_libri = dgrdLIBRI.DataKeys(e.Item.ItemIndex)

txtCodice_Rfid = e.Item.Cells(1).Controls(0)

TxtTitolo_del_libro = e.Item.Cells(2).Controls(0)

strCodice_Rfid = txtCodice_Rfid.Text

strTitolo_del_libro = TxtTitolo_del_libro.Text

strSql = "Update LIBRI Set Codice_Rfid=@Codice_Rfid, " &
"Titolo_del_libro=@Titolo_del_libro Where Id_libri=@Id_libri"

cmdSql = New SqlCommand(strSql, conDatabase_BIBLIOTECA)

cmdSql.Parameters.Add("@Codice_Rfid", strCodice_Rfid)

cmdSql.Parameters.Add("@Titolo_del_libro", strTitolo_del_libro)

cmdSql.Parameters.Add("@Id_libri", intId_libri)

conDatabase_BIBLIOTECA.Open()

cmdSql.ExecuteNonQuery()

conDatabase_BIBLIOTECA.Close()

dgrdLIBRI.EditItemIndex = -1

BindDataGrid()

End Sub

Sub dgrdLIBRI_CancelCommand(ByVal source As Object, ByVal e As
DataGridCommandEventArgs)

dgrdLIBRI.EditItemIndex = -1

BindDataGrid()

End Sub

End Class


<%@ Page Language="vb" AutoEventWireup="false" Codebehind="LIBRI3.aspx.vb"
Inherits="Biblioteca.WebForm9"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML>

<HEAD>

<title>WebForm9</title>

<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">

<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">

<meta name="vs_defaultClientScript" content="JavaScript">

<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">

</HEAD>

<body MS_POSITIONING="GridLayout">

<form id="Form1" method="post" runat="server">

<asp:DataGrid id="dgrdLIBRI" OnEditCommand="dgrdLIBRI_EditCommand"
OnUpdateCommand="dgrdLIBRI_UpdateCommand"

OnCancelCommand="dgrdLIBRI_CancelCommand" DataKeyField="Id_libri"
AutoGenerateColumns="False"

CellPadding="10" HeaderStyle-BackColor="Salmon" style="Z-INDEX: 101; LEFT:
360px; POSITION: absolute; TOP: 120px"

runat="server">

<Columns>

<asp:BoundColumn HeaderText="ID Libri" DataField="Id_libri" ReadOnly="True"
visible="False" />

<asp:BoundColumn HeaderText="Codice Rfid" DataField="Codice_Rfid" />

<asp:BoundColumn HeaderText="Titolo del libro" DataField="Titolo_del_libro"
/>

<asp:EditCommandColumn EditText="Edit!" UpdateText="Update!"
CancelText="Cancel!" />

</Columns>

</asp:DataGrid>

</form>

</body>

</HTML>


Nov 13 '06 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.