Saturday, November 29, 2008

Another bug in Visual Studio 2008 ?

I'm using VS 2008 with SP1...
For many, VS2008 is the best IDE for a programmers, but sometimes...

I was working with a GridView (previous post) and I had to change the name of a LinkButton from "Delete" to "Eliminate" a simple operation you could say... I also thought!
Unfortunately is not maintained the new "Text" property!
This problem does not exist with normal "Button", the property "Text" seems to work with this control and with the same conditions...

To perform the change, we need to go to the html source...

Friday, November 28, 2008

How to... use an Ajax ConfirmExtender in a GridView

A typical case to use an ajax-confirmbutton within a gridview is to delete a row on DB, let's take a look...

So, in our gridview, we have to create an "ItemTemplate", then add a LinkButton and the ajax ConfirmButtonExtender.
Set the property of our Extender like "TargetContolId" (= the LinkButton ID) and the "Confirm Text" (= Are You sure, continue?).
In this way we have connected the extender with the LinkButton !
Now we must connect the LinkButton with the data from the source (DataTable-method or a Control DataSource) in particular with an unic "row-ID"
Then go to Click-Event of the LinkButton to add the code to delete the row on DB...
something like:


Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
'delete after Ajax-ConfirmButtonExtender
Dim lb As LinkButton = sender
Dim objDel As New clSessionTest(("ConnectionString"))
objDel.EliTempTest(lb.CommandArgument)
objDel = Nothing
End Sub

Monday, November 3, 2008

How to… populate a dropdownlist

1. creare una vista sulla tabella da cui estrarre i dati (dal db AdventureWorks);
2. creare un dataset sulla vista;
3. creare un metodo in una classe per l'estrazione dei dati;
4. utilizzare il metodo e collegarlo alla DropDownList.

1.
Tramite Management Studio, aprire il db AdventureWorks. Visualizzare l'elenco delle "Viste" quindi crearne una di nuova sulla tabella Contact (Person).
I campi da fleggare sono: "ContactID, FirstName, LastName, Title".
Affinche' il risultato finale sia del tipo: "Mr. Gustavo Achong" suggerisco di editare il codice sql in questo modo:

SELECT ContactID, FirstName, LastName, Title, Title + N' ' + FirstName + N' ' + LastName AS [Full]
FROM Person.Contact



Salvare la Vista.

2.
Creare un DataSet e con la procedura guidata aggiungere un TableAdapter e collegare la vista appena creata con tutti i campi della vista (vw_get_persons).


Qui la procedura visualizza la vista...


3.
Creare un metodo in una classe:

Public Function GetDllPersons() As DataSet1.VW_GET_PERSONSDataTable

Dim sqlStatement As String
Dim cnn As SqlConnection = Nothing
Dim cmd As SqlCommand = Nothing
Dim da As SqlDataAdapter = Nothing

Try
sqlStatement = "SELECT * FROM VW_GET_PERSONS"
cnn = New SqlConnection(Me._connectionString)
cmd = New SqlCommand(sqlStatement, cnn)
da = New SqlDataAdapter(cmd)

cnn.Open()

_ds.VW_GET_PERSONS.Rows.Clear()
da.Fill(_ds, "VW_GET_PERSONS")
Catch ex As Exception
'todo: code for errors!
Finally
GetDllPersons = _ds.VW_GET_PERSONS
If Not (cnn Is Nothing) Then
cnn.Close()
cnn.Dispose()
cnn = Nothing
End If
If Not (da Is Nothing) Then
da.Dispose()
da = Nothing
End If
If Not (cmd Is Nothing) Then
cmd.Dispose()
cmd = Nothing
End If
End Try

End Function
4.
Nella pagina .aspx entrare nell'evento Page_Load e aggiungere questo codice:


If Not IsPostBack Then 'essenziale per evitare di caricare sempre gli stessi valori
Dim objGetdllPersons As Class1 = Nothing
objGetdllPersons = New Class1("Data Source=wolfdale;Initial Catalog=AdventureWorks; Integrated Security=True")
Me.ddl_Persons.DataSource = objGetdllPersons.GetDllPersons()
Me.ddl_Persons.DataTextField = "Full"
Me.ddl_Persons.DataValueField = "ContactID"
Me.ddl_Persons.DataBind()
End If


Quindi eseguire.

Sunday, November 2, 2008

Hello World


Dim Greeting As String = "Hello World"

2012 | aspnet code by Michele | don't try this at home
Mirko Iodice Notageek
Vladimir Carrer Carrer web log