Is it possible to use ADO.NET and ASP.NET databinding with textboxes , HELP!

L

Lloyd Sheen

I have several apps that use a roll your own approach, but I am embarking on
a project which will not allow that with the time constraints.

I have gened up a little app to try the databinding approach. Simply it is
a page to maintain the Territories table in Northwind (SQL Server).

I have two SqlDataAdaptors - one for the list of Territories
- on for the individual
Territories row (uses parameter to select)

I created the two datasets. So far so good. I can open the page bind to a
dropdownlist, and get the details into a set of textboxes for each field.

Now I also have a button which simply outputs the text of the update
command. It uses the
UpdateCommand.CommandText from the dataset.

How does databinding help with updates. All parameter values are nothing
when I click the button?

The code follows:

Public Class WebForm1
Inherits System.Web.UI.Page
#Region " Web Form Designer Generated Code "

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Me.TerritoryList.Fill(Me.DSTerritoryList)
Me.DropDownList1.DataBind()
End If
End Sub

Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
DropDownList1.SelectedIndexChanged
Me.OneTerritory.SelectCommand.Parameters(0).Value =
DropDownList1.SelectedItem.Value
Me.OneTerritory.Fill(Me.DsOneTerritory1)
Page.DataBind()
End Sub

Private Sub btnUpdateCommand_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnUpdateCommand.Click
Me.txtUpdateCommand.Text = Me.OneTerritory.UpdateCommand.CommandText
End Sub
End Class
 
M

Mythran

1.) Persist the dataset by using the ViewState (not recommended) or serialize and
store the dataset on the hard disk or store the dataset in the session. What I
do is just re-run the code to re-fill the dataset from the database after a
postback.

2.) Once dataset is re-filled, you re-bind the dataset to the controls which need
it.

3.) You now have the data in the combo and the index of the item in the combo
box. All of the above should be done on Page_Load (Form_Load) and should be
ready for the Click event when it gets there.



Mythran
 
L

Lloyd Sheen

Thanks but I am not sure what this would do for my problem. What I need is
to have a methodology of binding textboxes, making changes and having the
ability to click a button and have those changes update the database.

The dataadaptor has parameters in the updatecommand and how those parameters
would be updated with values is something I cannot figure out. Once I
rebind the dataset to the controls the updated info (that the user entered)
is lost.

Lloyd Sheen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top