Best way to populate a form with a DataList link?

  • Thread starter Thread starter Mal P
  • Start date Start date
M

Mal P

Hi there,

I'm a J2EE fellow who (as usual) has been thrown in the deep end and
have to learn a fair chunk of the .NET platform (VS, ADO, WebForms, C#
etc) in roughly two days. I'm doing ok so far, but am wondering on a
better way to do something...

Basically, I have a form which has a few fields the user fills in.
When submitted, the data is stored as a row in an SQL database table.
Then, I have another page which lists all the rows from that database
in tabular format. I use a DataList to do the displaying.

What I want to do is to have an "Edit" link next to each row which
will then go back to my original form, with all the fields populated
with the current values. The user can modify them, and re-submit.

I fiddled with the EditTemplate for the DataList but that's not what I
wanted - it seems to allow editing directly on my viewing only page. I
want the user to be re-directed to the separate form page. In the end,
due to a lack of time, I basically called the page with a get query
(i.e. formpage.aspx?report_id=45) and used the queryString to get the
report_id unique value of the record I wanted the fields in my form
populated with.

Anyone have a better suggestion on how to do this?

Thanks everyone,
Mal
 
Hi Mal
you need to read about dataset , datatable , dataview , and datagrid
objects as i think you should use them in such situation to get the best
result . you might need to read about these on MSDN online . also i
believe you would find many good examples on this site
http://www.codeproject.com/
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC.
 
Hi,

You need to know the "ID" of the record you selected, then with this ID you
can redirect it to the detail page and be able to fill the controls. There
are several ways of doing it, I describe you the solution more similar to
the way it was done in ASP

something like this:
... inside the DataList
<asp:button commandname="EditRecordHandler" commandargument="<%#
Container.DataItem["ID"] %>" Text="Edit"></asp:button>

and in the code behind:
protected void EditRecordHandler( object sender, CommandEventArgs e )
{
// you can also use a session variable here
Response.Redirect( "editrecord.aspx?id=" e.CommandArguments, true );
}


in the detail page you check if an ID is passed, if so you have to get this
record either from the DB or from a dataset and populate the fields as
needed.


Hope this help,
 
Back
Top