Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > One page - edit & insert

Reply
Thread Tools

One page - edit & insert

 
 
David Thielen
Guest
Posts: n/a
 
      04-08-2006
Hi;

I want to have a page where Datasource.aspx means create a new datasource
and Datasource.aspx?ID=5 means edit the datasource who's PK is 5.

I am not using a GridView or DetailsView for this data - there are a bunch
of dependencies so I have to just put in a bunch of form fields.

1) How do I best initialize all the fields when it is first called with ID=5?

2) How do I best tell the user if ID=5 and there is no record with a PK of 5?

3) If they come to the page once with ID=5, then type in the url
Datasource.aspx (no ID) - how do I handle this to turn it into a create? The
form appears to still be populated with the old values.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

 
Reply With Quote
 
 
 
 
Yuan Ren[MSFT]
Guest
Posts: n/a
 
      04-10-2006
Hi Dave,

Thanks for posting!

For the current issue, if you want to create a new data source which can
receive parameters, I think you can add the SqlDataSource object
programmatically in the Page_Load event and use the query string for the
SelectCommand property. The following fragment of the code is my sample:

protected void Page_Load(object sender, EventArgs e)
{
SqlDataSource mySqlDataSource = new SqlDataSource();
mySqlDataSource.ProviderName = "System.Data.SqlClient";
mySqlDataSource.ConnectionString = "Data Source=(local);Initial
Catalog=AdventureWorks;Integrated Security=True";
mySqlDataSource.SelectCommand = "select * from
[AdventureWorks].[Person].[Address]";
GridView1.DataSource = mySqlDataSource;
GridView1.DataBind();
}

>"How do I best tell the user if ID=5 and there is no record with a PK of

5?"
After calling DataBind function, please check the count of the GirdView
control and you will get the result of the current data source.

>"If they come to the page once with ID=5, then type in the url

Datasource.aspx (no ID) - how do I handle this to turn it into a create?
The form appears to still be populated with the old values."
My idea is also using the query string. And then, you can add your specific
logic code for the current requirement.

Hope this will be helpful!

Regards,

Yuan Ren
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights

 
Reply With Quote
 
 
 
 
David Thielen
Guest
Posts: n/a
 
      04-10-2006
Hello;

My question is more basic. I have a method to load the data into my object.
How do I then get that data into the fields?

And when the user clicks insert/update, how does it know if it is an insert
or an update?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



""Yuan Ren[MSFT]"" wrote:

> Hi Dave,
>
> Thanks for posting!
>
> For the current issue, if you want to create a new data source which can
> receive parameters, I think you can add the SqlDataSource object
> programmatically in the Page_Load event and use the query string for the
> SelectCommand property. The following fragment of the code is my sample:
>
> protected void Page_Load(object sender, EventArgs e)
> {
> SqlDataSource mySqlDataSource = new SqlDataSource();
> mySqlDataSource.ProviderName = "System.Data.SqlClient";
> mySqlDataSource.ConnectionString = "Data Source=(local);Initial
> Catalog=AdventureWorks;Integrated Security=True";
> mySqlDataSource.SelectCommand = "select * from
> [AdventureWorks].[Person].[Address]";
> GridView1.DataSource = mySqlDataSource;
> GridView1.DataBind();
> }
>
> >"How do I best tell the user if ID=5 and there is no record with a PK of

> 5?"
> After calling DataBind function, please check the count of the GirdView
> control and you will get the result of the current data source.
>
> >"If they come to the page once with ID=5, then type in the url

> Datasource.aspx (no ID) - how do I handle this to turn it into a create?
> The form appears to still be populated with the old values."
> My idea is also using the query string. And then, you can add your specific
> logic code for the current requirement.
>
> Hope this will be helpful!
>
> Regards,
>
> Yuan Ren
> Microsoft Online Community Support
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights
>
>

 
Reply With Quote
 
Yuan Ren[MSFT]
Guest
Posts: n/a
 
      04-12-2006
Hi Dave,

Thanks for your reply!

>"I have a method to load the data into my object."

I want to know which specific object you have used for the current issue.
From your description, you use the SqlDataSource object, if I have any
unclear, please let me know. In my opinion, the SqlDataSource is designed
for the SQL Server database functionality. It isn't like the DataSet
object. So, if you want to perform some action for the data, I recommend
you use the DataSet object in this scenario.

>"And when the user clicks insert/update, how does it know if it is an

insert or an update?"
Actually, this is an internal implementation of the SqlDataSource control.
When you set the select command or the update command for the SqlDataSource
control, the SqlDataSource control will execute the select or the update
method for data binding. These methods will be implemented by the
SqlDataSourceView control. The model of the new control is like the
DataAdapter object does but actually not. This is only for convenience of
the developer. If you want to use the old way likes ASP.NET v1.1, the
functionality is also implement without problem.

Hope this will be helpful!

Regards,

Yuan Ren
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
David Thielen
Guest
Posts: n/a
 
      04-12-2006
Hi;

I would like to use an ObjectDataSource which calls to a class I have
created. The basic issue here I think is I am trying to use one page for edit
& insert without using a FormView. The advantage of this is the controls are
the same instead of having to list them twice and they are directly
accessable in the code behind.

But this means there is no container type control like FormView to tie the
data to.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com



""Yuan Ren[MSFT]"" wrote:

> Hi Dave,
>
> Thanks for your reply!
>
> >"I have a method to load the data into my object."

> I want to know which specific object you have used for the current issue.
> From your description, you use the SqlDataSource object, if I have any
> unclear, please let me know. In my opinion, the SqlDataSource is designed
> for the SQL Server database functionality. It isn't like the DataSet
> object. So, if you want to perform some action for the data, I recommend
> you use the DataSet object in this scenario.
>
> >"And when the user clicks insert/update, how does it know if it is an

> insert or an update?"
> Actually, this is an internal implementation of the SqlDataSource control.
> When you set the select command or the update command for the SqlDataSource
> control, the SqlDataSource control will execute the select or the update
> method for data binding. These methods will be implemented by the
> SqlDataSourceView control. The model of the new control is like the
> DataAdapter object does but actually not. This is only for convenience of
> the developer. If you want to use the old way likes ASP.NET v1.1, the
> functionality is also implement without problem.
>
> Hope this will be helpful!
>
> Regards,
>
> Yuan Ren
> Microsoft Online Community Support
> ==================================================
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
> ==================================================
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>

 
Reply With Quote
 
Yuan Ren[MSFT]
Guest
Posts: n/a
 
      04-14-2006
Hi Dave,

Thanks for your reply!

As I mentioned before, if you don't want to use the new control in ASP.NET
v2.0, you can use the old way like we do in ASP.NET v1.1. So, we can update
or insert our record to the database by using the SqlDataAdapter class in
other pages which you want to build by yourself. Please tell me about your
concern to use the old way. Thanks!

Regards,

Yuan Ren
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert Multiple Records Using One Insert Statemen with MySQLdb module anton.ranieri.it@gmail.com Python 1 12-06-2008 12:47 PM
I have one ASP.NET Page. It's for display customer information. Now I want this page to handle the function "Edit" and "Display", Is it possible? Benny Ng ASP .Net 1 01-04-2007 08:00 PM
Snapshot restraint - edit, edit, edit Alan Browne Digital Photography 24 05-10-2005 10:15 PM
Snapshot restraint - edit, edit, edit Patrick Digital Photography 0 05-06-2005 10:53 PM
copying value of DDL in a Datagrid "pre-edit command" to value in "post edit command" San Diego Guy ASP .Net 0 08-07-2003 08:59 PM



Advertisments