Create ObjectDataSource from passed in DataSet
-
I am trying to implement the new GridView control in my ASP.Net 2.0 website. I am using C# 3.0 as my CodeBehind. I have a third party grid control that allows me to dynamically expand and collapse child records. I can fully control how the "Child" records are displayed. The problem that I am having is that I want to show the child records in a GridView control, and use it's functionality to edit the child records. So far, I have been able to bind my records using the following:
protected void Detail_DataBinding(object sender, System.EventArgs e) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("DetailID,"); sb.Append("MasterID,"); sb.Append("Detail_Status_Code,"); sb.Append("Status_Change_Date,"); sb.Append("SupervisorID,"); sb.Append("Supervisor_Login_ID,"); sb.Append("Supervisor_Notes"); DataGridItem dgi = (DataGridItem)this.BindingContainer; DataSet ds = (DataSet)dgi.DataItem; dtlGrid.DataSource = ds; dtlGrid.DataMember = "DiscrepDetail"; dtlGrid.DataKeyNames = sb.ToString(); dtlGrid.DataBind(); }
This allows me to show the child records. I have then added Custom Event Handlers in the OnInit function:override protected void OnInit(EventArgs e) { this.DataBinding += new System.EventHandler(this.Detail_DataBinding); this.dtlGrid.RowEditing += new GridViewEditEventHandler(dtlGrid_RowEditing); this.dtlGrid.RowCancelingEdit += new GridViewCancelEditEventHandler(dtlGrid_RowCance
-
I am trying to implement the new GridView control in my ASP.Net 2.0 website. I am using C# 3.0 as my CodeBehind. I have a third party grid control that allows me to dynamically expand and collapse child records. I can fully control how the "Child" records are displayed. The problem that I am having is that I want to show the child records in a GridView control, and use it's functionality to edit the child records. So far, I have been able to bind my records using the following:
protected void Detail_DataBinding(object sender, System.EventArgs e) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("DetailID,"); sb.Append("MasterID,"); sb.Append("Detail_Status_Code,"); sb.Append("Status_Change_Date,"); sb.Append("SupervisorID,"); sb.Append("Supervisor_Login_ID,"); sb.Append("Supervisor_Notes"); DataGridItem dgi = (DataGridItem)this.BindingContainer; DataSet ds = (DataSet)dgi.DataItem; dtlGrid.DataSource = ds; dtlGrid.DataMember = "DiscrepDetail"; dtlGrid.DataKeyNames = sb.ToString(); dtlGrid.DataBind(); }
This allows me to show the child records. I have then added Custom Event Handlers in the OnInit function:override protected void OnInit(EventArgs e) { this.DataBinding += new System.EventHandler(this.Detail_DataBinding); this.dtlGrid.RowEditing += new GridViewEditEventHandler(dtlGrid_RowEditing); this.dtlGrid.RowCancelingEdit += new GridViewCancelEditEventHandler(dtlGrid_RowCance
Hi, I would suggest you to use Dataset.xsd, Instead of Creating your own. You just have to Add a DataSet by "Add New Item..." From Solution Explorer. After that Just Configure the query or Select the Stored procedure to use for Dataset. But if you want to use ObjectDataSource with your own SelectMethod then You need to Change the TypeName Property to the name of the class that contains the Method Specified in SelectMethod. Write in case of further Help. Thank you.
-
Hi, I would suggest you to use Dataset.xsd, Instead of Creating your own. You just have to Add a DataSet by "Add New Item..." From Solution Explorer. After that Just Configure the query or Select the Stored procedure to use for Dataset. But if you want to use ObjectDataSource with your own SelectMethod then You need to Change the TypeName Property to the name of the class that contains the Method Specified in SelectMethod. Write in case of further Help. Thank you.
My problem is that I am creating a bunch of Child controls, and the Parent is giving them the records that they need to display. I retrieve my DataSet in this way:
DataSet myDS = (DataSet)((DataGridItem)this.BindingContainer).DataItem;
I can get single fields in each row in my ASP by using this:<asp:Label ID="lblDetailStatus" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Short_Desc").ToString() %>' />
I don't actually have a class that I can point the ObjectDataSource at. If I used the DataSet.xsd, is there a way to populate it at Run-Time? And how would I create code to update my records? Thanks. -
My problem is that I am creating a bunch of Child controls, and the Parent is giving them the records that they need to display. I retrieve my DataSet in this way:
DataSet myDS = (DataSet)((DataGridItem)this.BindingContainer).DataItem;
I can get single fields in each row in my ASP by using this:<asp:Label ID="lblDetailStatus" runat="server" Text='<%#DataBinder.Eval(Container.DataItem, "Short_Desc").ToString() %>' />
I don't actually have a class that I can point the ObjectDataSource at. If I used the DataSet.xsd, is there a way to populate it at Run-Time? And how would I create code to update my records? Thanks.hi, Once you create a DataSet.Xsd, You need to add a Table Adapter. Just Drag and Drop from Tool Box if they do not add automatically for you. Follow the steps and It will also generate Methods for Update and Delete the record for you. Now, You just have to go to Design mode of your .Aspx page and configure the ObjectDataSource control to select methods to select, Update and Delete records. Just Give it a try. I am not sure if this is what you need. Can you not use GridView instead of DataGrid?? Thanks.
-
hi, Once you create a DataSet.Xsd, You need to add a Table Adapter. Just Drag and Drop from Tool Box if they do not add automatically for you. Follow the steps and It will also generate Methods for Update and Delete the record for you. Now, You just have to go to Design mode of your .Aspx page and configure the ObjectDataSource control to select methods to select, Update and Delete records. Just Give it a try. I am not sure if this is what you need. Can you not use GridView instead of DataGrid?? Thanks.
I am using the GridView. The problem that I will run into with creating the XSD file will be from the "Select" method. The control where I am displaying my GridView is just a control, not a web page. The parent page will hand the child control a DataSet for it to work with. The control itself is Bound to the parent. Think about it this way: I have a stored procedure that brings back a DataSet with 2 tables. Customers and Orders. The main page uses a repeater control that displays each Customer. The Customer control will now pass all of the Orders (zero - to - many) for this Customer to yet another control (this control is a "re-usable" object that I have created as a seperate class) that has my GridView in it. I want to give the Order control the ability to edit the Orders. My Orders control can not use a "Select" method because the records have already been handed to it. How do I accomplish this?
-
I am trying to implement the new GridView control in my ASP.Net 2.0 website. I am using C# 3.0 as my CodeBehind. I have a third party grid control that allows me to dynamically expand and collapse child records. I can fully control how the "Child" records are displayed. The problem that I am having is that I want to show the child records in a GridView control, and use it's functionality to edit the child records. So far, I have been able to bind my records using the following:
protected void Detail_DataBinding(object sender, System.EventArgs e) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("DetailID,"); sb.Append("MasterID,"); sb.Append("Detail_Status_Code,"); sb.Append("Status_Change_Date,"); sb.Append("SupervisorID,"); sb.Append("Supervisor_Login_ID,"); sb.Append("Supervisor_Notes"); DataGridItem dgi = (DataGridItem)this.BindingContainer; DataSet ds = (DataSet)dgi.DataItem; dtlGrid.DataSource = ds; dtlGrid.DataMember = "DiscrepDetail"; dtlGrid.DataKeyNames = sb.ToString(); dtlGrid.DataBind(); }
This allows me to show the child records. I have then added Custom Event Handlers in the OnInit function:override protected void OnInit(EventArgs e) { this.DataBinding += new System.EventHandler(this.Detail_DataBinding); this.dtlGrid.RowEditing += new GridViewEditEventHandler(dtlGrid_RowEditing); this.dtlGrid.RowCancelingEdit += new GridViewCancelEditEventHandler(dtlGrid_RowCance
Hi there, I believe that you're still able to handle the RowCancelingEdit and RowUpdating events of the GridView control, and for the RowUpdated event you will need a datasource control to use with the grid control. From what I see in your sample code, you're binding data to the grid control using the DataBinding event handler, so I guess will need to call the DataBind method somewhere to make the DataBinding event get fired. And I doubt that it might be causing the issue if you're not calling it the right way, so can you tell me how do you use this control in its parent and how do you call the DataBind method to bind data? Also, can you check if the RowCommand event gets fired or not?
Bryan Clauss wrote:
I am using C# 3.0
Wow, it seems you're very quick in applying the new extensions in the version 3.0.