One page - edit & insert

Discussion in 'ASP .Net Web Controls' started by David Thielen, Apr 8, 2006.

  1. 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
     
    David Thielen, Apr 8, 2006
    #1
    1. Advertising

  2. 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
     
    Yuan Ren[MSFT], Apr 10, 2006
    #2
    1. Advertising

  3. 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
    >
    >
     
    David Thielen, Apr 10, 2006
    #3
  4. 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.
     
    Yuan Ren[MSFT], Apr 12, 2006
    #4
  5. 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.
    >
    >
     
    David Thielen, Apr 12, 2006
    #5
  6. 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.
     
    Yuan Ren[MSFT], Apr 14, 2006
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. San Diego Guy
    Replies:
    0
    Views:
    581
    San Diego Guy
    Aug 7, 2003
  2. Schultz
    Replies:
    3
    Views:
    595
    =?Utf-8?B?QmlsbCBCb3Jn?=
    Feb 14, 2005
  3. =?Utf-8?B?a2Vu?=
    Replies:
    1
    Views:
    10,391
    Wiktor Zychla [C# MVP]
    Jan 23, 2006
  4. Replies:
    1
    Views:
    1,870
    Albert Hopkins
    Dec 6, 2008
  5. Sharon McCarty
    Replies:
    0
    Views:
    278
    Sharon McCarty
    Nov 24, 2004
Loading...

Share This Page