|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
One page - edit & insertI 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. 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 After calling DataBind function, please check the count of the GirdView 5?" 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 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? Show quoteHide quote > 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 > > 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. 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. Show quoteHide quote > 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. > > 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.
DataMappingType in the DataSet Designer
UserControls and Collections Property I do I remove the style attribute from Image controls? HyperLinkField and FindControl using 'sender' object on event fires FormView - initial template Problem in designing layout of website UserControl project or website location in design time Gridview can't format a date |
|||||||||||||||||||||||