469,909 Members | 1,762 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,909 developers. It's quick & easy.

like avoiding to always insert the same elements

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.


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


End If

End Sub

Sub BindDataGrid()

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


dgrdLIBRI.DataSource = cmdSql.ExecuteReader



End Sub

Sub dgrdLIBRI_EditCommand(ByVal source As Object, ByVal e As

dgrdLIBRI.EditItemIndex = e.Item.ItemIndex


End Sub

Sub dgrdLIBRI_UpdateCommand(ByVal source As Object, ByVal e As

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)




dgrdLIBRI.EditItemIndex = -1


End Sub

Sub dgrdLIBRI_CancelCommand(ByVal source As Object, ByVal e As

dgrdLIBRI.EditItemIndex = -1


End Sub

End Class

<%@ Page Language="vb" AutoEventWireup="false" Codebehind="LIBRI3.aspx.vb"

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




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


<body MS_POSITIONING="GridLayout">

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

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

OnCancelCommand="dgrdLIBRI_CancelCommand" DataKeyField="Id_libri"

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



<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!" />






Nov 13 '06 #1
0 1255

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

18 posts views Thread by Bill Smith | last post: by
1 post views Thread by subramanian100in | last post: by
2 posts views Thread by subramanian100in | last post: by
5 posts views Thread by John Doe | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.