Page view counter

Dataset + ObjectDatasource + GridView + ASP.NET 2

Rate It (2)

Last post 12-18-2008 11:58 AM by JustWantAnAnswer. 40 replies.

Sort Posts:

  • Dataset + ObjectDatasource + GridView + ASP.NET 2

    11-10-2005, 1:44 PM
    • Loading...
    • ccw3
    • Joined on 05-10-2005, 10:23 PM
    • Posts 8
    • Points 40
    I have a table as follows
    TableName: banner_type
    Columns banner_type_id (bigint) , name (varchar(200)), description(text)

    1. I created a DataSet for this table with VisualStudio2005
    2. I generated automatically select, insert, delete and update commands for this table (without concurrency support)
    3. I created a page "add_banner_type.aspx" with a GridView + ObjectDataSource that uses my DataSet
    4. The gridview selects all columns in the database, but If I try to update or delete , I get an error:

    ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Update' that has parameters: name, description, original_banner_type_id.


    I thought it should worked directly??? What am I doing wrong?


  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    11-11-2005, 8:00 PM
    • Loading...
    • irinelc
    • Joined on 06-11-2002, 12:32 PM
    • Redmond, WA
    • Posts 214
    • Points 1,070
    • AspNetTeam
    Hi

    There are several things to check:
    1. I am assuming that there is a primary key set in the table (it is needed for the update and delete operation). Let's call this primary key id (so it is easier to get to the point)
    2. Make sure that on the GridViewthe DataKeyName property is already set to the id
    3. Select the GridView, click on the EditColumns task in the chrome and select the id boun field. We need to make sure the ReadOnly property of the primary key is set to false.

    Hope this helps
    Irinel
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    11-12-2005, 11:39 AM
    • Loading...
    • ccw3
    • Joined on 05-10-2005, 10:23 PM
    • Posts 8
    • Points 40
    OK, I set the primary key (banner_type_id), to read_only = true . But it doesn't make sense to enable editing of the primary key. Anyway, now I get a different error:

    Value cannot be null.
    Parameter name: Original_name


    Why do I get this error? Below is my object DataSource definition and GridView
    <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" DeleteMethod="Delete"
            InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
            TypeName="gremioTableAdapters.banner_typeTableAdapter" UpdateMethod="Update">
            <DeleteParameters>
                <asp:Parameter Name="Original_banner_type_id" Type="Int64" />
                <asp:Parameter Name="Original_name" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="name" Type="String" />
                <asp:Parameter Name="description" Type="String" />
                <asp:Parameter Name="Original_banner_type_id" Type="Int64" />
                <asp:Parameter Name="Original_name" Type="String" />
                <asp:Parameter Name="banner_type_id" Type="Int32" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="name" Type="String" />
                <asp:Parameter Name="description" Type="String" />
            </InsertParameters>
        </asp:ObjectDataSource>

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="banner_type_id"
            DataSourceID="ObjectDataSource1">
            <Columns>
                <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
                <asp:BoundField DataField="banner_type_id" HeaderText="banner_type_id" InsertVisible="False"
                    SortExpression="banner_type_id" />
                <asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
                <asp:BoundField DataField="description" HeaderText="description" SortExpression="description" />
            </Columns>
        </asp:GridView>


  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    11-13-2005, 11:34 PM
    • Loading...
    • irinelc
    • Joined on 06-11-2002, 12:32 PM
    • Redmond, WA
    • Posts 214
    • Points 1,070
    • AspNetTeam
    The thing here is that the parameters in the methods in the xsd do not match the parameters in the aspx. Let's try again and re-generate the data set (go through the steps you described in the first post starting from a as clean as possible state - i.e. delete the data set and the object data source and the grid). After the last step, select the grid and change the bound field corresponding to the primary key read only property to false.

    Hope this helps
    Irinel 
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    11-14-2005, 12:48 PM
    • Loading...
    • ccw3
    • Joined on 05-10-2005, 10:23 PM
    • Posts 8
    • Points 40
    I did it about 20 times, sometimes it works for somethings, but mostly doesn't work.
    What I don't understand is why the primary key should be editable?

  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    11-14-2005, 2:39 PM
    • Loading...
    • irinelc
    • Joined on 06-11-2002, 12:32 PM
    • Redmond, WA
    • Posts 214
    • Points 1,070
    • AspNetTeam
    You are right: in most cases we don't make it editable. But for this we need to change the list of parameters in the aspx and/or handle the *ing event to make the parameters in sync with the xsd generated ones

    Hope this helps
    Irinel
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    12-01-2005, 11:03 AM
    • Loading...
    • willc
    • Joined on 08-24-2002, 11:00 AM
    • Posts 36
    • Points 170

    Does this even work? I created a Dataset/TableAdapter and have it create the stored procedures. Using DetailsView and Objectsource controls, the Select statement works but the generated Update statement produces the error:

    ObjectDataSource 'ObjectDataSource1' could not find a non-generic method 'Update' that has parameters....

    This is using the code that the IDE produces with no modifications..

  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    12-01-2005, 12:53 PM
    • Loading...
    • irinelc
    • Joined on 06-11-2002, 12:32 PM
    • Redmond, WA
    • Posts 214
    • Points 1,070
    • AspNetTeam
    Hi 
     
    The Update and Delete operations are special as they need a primary key value. That's why, at the end of the wizard run, we need to make sure that the parameters that we have generated in the aspx page match the parameters in the xsd. So, at the end of the wizard run, do the verifications I enumerated in the precedent post. It should solve your problem...

    Hope this helps
    Irinel
    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    12-01-2005, 6:33 PM
    • Loading...
    • codingCamel
    • Joined on 12-01-2005, 11:30 PM
    • Posts 1
    • Points 5
    I had the exact same problem. when i looked at the databindings for the ID field in the gui tool i noticed that the two way binding was unselected.
    so i ticked the box and now it works :)  
    hope this helps

  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    01-26-2006, 8:35 PM
    • Loading...
    • tbcarver
    • Joined on 06-20-2005, 4:11 PM
    • Posts 60
    • Points 272
    irinelc wrote:

    3. Select the GridView, click on the EditColumns task in the chrome and select the id boun field. We need to make sure the ReadOnly property of the primary key is set to false.
    Irinel


    I had the same issue and setting the ReadOnly to false fixed it.  However, this seems like a workaround.  I want the property to be read only because it is an auto number and cannot be changed.  What is the real problem here?  Does it have something to do with two way binding?  It seems very reasonable and right to use the read only property because this is for the UI and it is read only.

    I thought this sounded good:
    codingCamel wrote:
    I had the exact same problem. when i looked at the databindings for the ID field in the gui tool i noticed that the two way binding was unselected.
    so i ticked the box and now it works :)  

    But I have no idea what he is actually did or what he is talking about.

    How can I fix this in a reasable way?

    Thanks for your help,
    Tyler
  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    02-14-2006, 5:00 AM
    • Loading...
    • sandy35
    • Joined on 02-12-2006, 4:57 AM
    • Posts 2
    • Points 10

    I agree with Tyler.

    I have found two ways to make the parameters match for the generated update statement and the gridview/detailsview update method. One, to make the primary field editable (as above) or two to create your own update method that does not pass the last parameter. However, both these methods are work arounds. I believe this is a bug.

    Whats more, when i try and generate stored procedures with their methods from the dataset designer and untick the return select statements for update methods, it generates the select statements anyway. And you cant modify the generated class from the back end because it gets overwritten at run time.

    I think microsoft should address this in their next service pack release.

    Regards

    Sandy

  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    02-15-2006, 5:50 PM
    • Loading...
    • markman
    • Joined on 02-14-2006, 1:53 AM
    • Posts 5
    • Points 25

    adding 'DataKeyNames=??' to the detailsview allows you to have your primary key readonly and have the id avaiblable for updates.

    Markus

  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    02-22-2006, 8:23 AM
    • Loading...
    • george.polevoy
    • Joined on 02-02-2006, 3:20 PM
    • Posts 6
    • Points 30

    Say you have a table: (client_id /*primary key guid*/, [client_name, ...] )

    I've got an auto-generated DataSet and a GridView updatable in two steps:

    1. Select the ObjectDataSource in the designer. Press F4 to display Properties floater if it's not already displayed. Find the UpdateParameters (Collection) ... property, enter the "..." button to open the "Parameter Collection Editor", select the primary key column, ("client_id" in my case). Click the "Show advanced properties" link button (yet can't figure out what's so advanced about it). For the "Direction" property select "InputOutput"

    2. Select the GridView object in the designer. Open the "Grid View Tasks" (small triangle arrow button at the top-right of the control)  / "Edit Columns" / "Fields" window. In the "Selected Fields" list, select the "client_id". In the "Bound Field properties" for the "ReadOnly" property select "True".

    Done

    Sorry to be too "down and dirty" at this, but i have to, since we are talking about the "wizards and magic" Smile [:)]

    To ASPNET Team:

    IMHO, requirement for a property to be writable just to be able to send it for concurency resolution purpose, when it's actually readonly being a primary key, is an error.

  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    02-23-2006, 10:54 AM
    • Loading...
    • jpv
    • Joined on 02-23-2006, 3:36 PM
    • Posts 2
    • Points 10

    Thanks to george for a great post.

    Just to note that the ReadOnly property must be set to FALSE not true. ie. that it is editable.

  • Re: Dataset + ObjectDatasource + GridView + ASP.NET 2

    02-27-2006, 4:39 AM
    • Loading...
    • stevenR2
    • Joined on 12-20-2005, 2:09 PM
    • Glasgow, Scotland
    • Posts 18
    • Points 90

    I have run into this problem and  i have to say it is not a great solution - that is to make a primary key (or in my case a composite key) readonly just to enable an update. I'm sure this must open up some kind of security hole and allow client side modification or the primary id's.

    Another workaround is to use a TemplateField and so on with Eval and Bind, but then what is the point of BoundField? Very limited i'd say. The InsertVisible property is cool, so why not have an UpdateVisible property too?

    Just to note however, that I always wrote things procedurally and avoided DataBinding, but some of the work done is amazing and bar one or two complaints, i am hooked. The problem is my one or two complaints are fairly fundamental things (don't get me started on ControlParameters!!).

    steven :: http://stevenR2.com
Page 1 of 3 (41 items) 1 2 3 Next >