Dropdown database bound - simple screen with only dropdownbox, bestway to solve it [newby]

P

Pietje puk

Hello,

Since im quite new to ASP.NET i wanted to ask you folks what the best
way is to create a WebForm for modifying 1 field from a record. The
manipulation of this field can be done by using dropdown list.

Previously i've written a lot of these page's by not using the
webcontrols, but now i've reached this magically moment that i want to
try these features. :D

In short, the program exists of 1 table, called "details" and another,
which is called "lookup". The aspx page is started with the parameter
key. So the call will be the following:

http://localhost/aspcontrols/DetailsEdit.aspx?key=1234

My current code:
================
- Added OleDbConnection to the webform
- Connection String is retrieved from web.config (done by adjusting
dynamic properies)

- Added a DataAdapter (for the details table)
- Modified the SelectCommand in such a way that it needs an
CommandParameter.

- Added a DataAdapter (for the lookup table) (only select command)

- Generated a DataSet for both table's in DataDefinitions DataSet

- Added the DataDefinitions DataSet to the webform

- Added a dropdown to the webform
Properties:
- DataMember = lookup
- DataSource = dataSet
- DataTextField = lookupfield
Databindings:
-SelectedValue = Simple Binding: dataSet -> Details -> [..] -> field

- Added a button to the form with the following code:
detailsDataAdapter.Update(dataSet);

- Added a method PageLoad with the following code:
private void Page_Load(object sender, System.EventArgs e)
{
if(Request.Params["key"] == null)
{
throw new HttpException("Parameter 'key' is missing");
}
if (!this.IsPostBack )
{ oleDbSelectCommand.Parameters["key"].Value
= Request.Params["key"];
detailsDataAdapter.Fill(dataSet);
if(dataSet.Tables["details"].Rows.Count != 1) throw new
HttpException("Did not find 1 record for key:" + Request.Params["key"]);
lookupDataAdapter.Fill(dataSet);
dropdown.DataBind();
}
}
Problems:
================
- Value of the current value is not set in the dropdown list
- When i press the button, i dont have the any data in the dataset.

Question:
================
- What should i change in the current situation to make it work
- What is the -best- way to create such a page (sample's / pointers)
- Is it wise to use the databinding? Lots of examples use an iteration
to put the data in the dropdown box
- How do i close the window after is saved the data?

Eduard Witteveen
 

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,767
Messages
2,569,572
Members
45,045
Latest member
DRCM

Latest Threads

Top