D
djc
I had previously (in asp.net 1.1 and asp.net web matrix) just done this to
populate a listbox with data from a database:
------------ this was from the page load event ----------------
'fill recipient address list box
Dim cnn As SqlConnection
cnn = New SqlConnection(Application("cnn").ToString())
Dim cmdGetAllRecipientAddresses As SqlCommand = New
SqlCommand("GetAllRecipientAddresses", cnn)
cmdGetAllRecipientAddresses.CommandType = CommandType.StoredProcedure
cnn.Open()
Me.lstAvailableRecipients.DataSource =
cmdGetAllRecipientAddresses.ExecuteReader(CommandBehavior.CloseConnection)
Me.lstAvailableRecipients.DataTextField = "EmailAddress"
Me.lstAvailableRecipients.DataValueField = "EmailAddress"
Me.lstAvailableRecipients.DataBind()
--------------------------------------------------------------
Now I'm playing with 2.0 and VS 2005 and see this 'SqlDataSource' class.
1) Is this now the preferred/suggested method for binding data to
listboxes/datagrids etc...?
2) I'm not clear on its intended scope of usage: for instance if I have
several different databound controls in my asp.net page would I drag one
SqlDataSource from the toolbox for each of those controls? or would I use
just one and programmatically adjust properties (esentially the store
procedure I want to run)?
I'm just starting a new project (only hobby) and didn't want to get to far
into it using the method I was already familiar with if this new method is
preferred. This is mainly just hobby for me but I still like to follow
recommended practices. Any input would be appreciatd.
populate a listbox with data from a database:
------------ this was from the page load event ----------------
'fill recipient address list box
Dim cnn As SqlConnection
cnn = New SqlConnection(Application("cnn").ToString())
Dim cmdGetAllRecipientAddresses As SqlCommand = New
SqlCommand("GetAllRecipientAddresses", cnn)
cmdGetAllRecipientAddresses.CommandType = CommandType.StoredProcedure
cnn.Open()
Me.lstAvailableRecipients.DataSource =
cmdGetAllRecipientAddresses.ExecuteReader(CommandBehavior.CloseConnection)
Me.lstAvailableRecipients.DataTextField = "EmailAddress"
Me.lstAvailableRecipients.DataValueField = "EmailAddress"
Me.lstAvailableRecipients.DataBind()
--------------------------------------------------------------
Now I'm playing with 2.0 and VS 2005 and see this 'SqlDataSource' class.
1) Is this now the preferred/suggested method for binding data to
listboxes/datagrids etc...?
2) I'm not clear on its intended scope of usage: for instance if I have
several different databound controls in my asp.net page would I drag one
SqlDataSource from the toolbox for each of those controls? or would I use
just one and programmatically adjust properties (esentially the store
procedure I want to run)?
I'm just starting a new project (only hobby) and didn't want to get to far
into it using the method I was already familiar with if this new method is
preferred. This is mainly just hobby for me but I still like to follow
recommended practices. Any input would be appreciatd.