Error -System.NotSupportedException: Specified method is not supported.

Last post 08-08-2008 5:14 PM by pluns. 12 replies.

Sort Posts:

  • Error -System.NotSupportedException: Specified method is not supported.

    12-12-2005, 5:07 PM
    • Member
      595 point Member
    • danh74
    • Member since 11-13-2004, 7:50 PM
    • Posts 126

    hi,

    I am using GridView and XmlDataSource to display and edit XML file.

    The error happen while i am in the update event handler (OnRowUpdating).

    I notice that the error happen even if there is noting in the event handler.

    I have no idea what the problem is.

    TIA

  • Re: Error -System.NotSupportedException: Specified method is not supported.

    12-13-2005, 2:04 AM
    • Member
      595 point Member
    • danh74
    • Member since 11-13-2004, 7:50 PM
    • Posts 126

    can someone  help here please.

    TIA

  • Re: Error -System.NotSupportedException: Specified method is not supported.

    12-13-2005, 2:34 AM
    • Contributor
      5,535 point Contributor
    • Eilon
    • Member since 06-26-2002, 6:14 PM
    • Redmond, WA
    • Posts 951
    • AspNetTeam

    The XmlDataSource does not support updating. Of the data sources that ship with ASP.net 2.0 only SqlDataSource and ObjectDataSource support insert/update/delete.

     

    Thanks,

    Eilon

     

    Blog: http://weblogs.asp.net/LeftSlipper/
  • Re: Error -System.NotSupportedException: Specified method is not supported.

    12-13-2005, 2:47 AM
    • Member
      595 point Member
    • danh74
    • Member since 11-13-2004, 7:50 PM
    • Posts 126

    In the msdn Microsoft say it can.

    http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.xmldatasource.aspx

    The XmlDataSource can return XmlDataDocument and it also have Save function.

    This is very strange error i have here.

    i am getting the error even if the function is empty , but while i am adding

     Response.Write("someText");

    Response.End();

    I am getting no error.

    While i am removing the Response.End(); i am getting the error again.

    TIA

  • Re: Error -System.NotSupportedException: Specified method is not supported.

    12-13-2005, 3:03 AM
    • Contributor
      5,535 point Contributor
    • Eilon
    • Member since 06-26-2002, 6:14 PM
    • Redmond, WA
    • Posts 951
    • AspNetTeam

    I'm sorry, what I meant was that the data source does not support automatic insert/update/delete through its IDataSourceControl/DataSourceView interfaces, which is what GridView uses. What you can do is handle the GridView's RowUpdating event, manually update the XML data in the XmlDataSource by calling GetXmlDocument(), call the Save() method, and finally cancel the RowUpdating event (so that the GridView doesn't try to make the data source do an automatiac update).

    The reason you don't get an error when you call Response.End() is that it does exactly that - it ends the response - so the XmlDataSource never has a chance to throw its exception.

    Thanks,

    Eilon

    Blog: http://weblogs.asp.net/LeftSlipper/
  • Re: Error -System.NotSupportedException: Specified method is not supported.

    12-13-2005, 3:09 AM
    • All-Star
      29,644 point All-Star
    • Fredrik N
    • Member since 06-22-2002, 5:03 AM
    • Sweden
    • Posts 5,334
    • TrustedFriends-MVPs

    If you use an XmlDataSource control and added an Update command button to update the Row, you will get the NotSupported exception because the GridView will call the Update method of the XmlDataSource's XmlDataSourceView. The XmlDataSource don't support updates and of that reason the XmlDataSourceView's Update method will throw the NotSupported Exception.

    To remove the exception you have to cancel the RowUpdate by setting the event argument's Cancel property to true. By doing that the XmlDataSourceView's Update method will not be called.

    The only way to update the document when you use the XmlDataSource is to add the update logic to the RowUpdating event by your self (You need to handle the update). I have an example on my blog where I use the XmlDataSource to update the XML document; it can probably give you some idea:

     http://fredrik.nsquared2.com/viewpost.aspx?PostID=270

    /Fredrik Normén - fredrikn @ twitter

    ASPInsider

    Microsoft MVP, MCSD, MCAD, MCT

    ASPInsiders
    My Blog
  • Re: Error -System.NotSupportedException: Specified method is not supported.

    12-13-2005, 3:10 AM
    • Member
      595 point Member
    • danh74
    • Member since 11-13-2004, 7:50 PM
    • Posts 126

    What you can do is handle the GridView's RowUpdating event, manually update the XML data in the XmlDataSource by calling GetXmlDocument(), call the Save() method,

    I did exactly that

    and finally cancel the RowUpdating event (so that the GridView doesn't try to make the data source do an automatiac update).

    Can you explain how can i do it?

    TIA

     

  • Re: Error -System.NotSupportedException: Specified method is not supported.

    05-01-2006, 7:46 PM
    • Member
      30 point Member
    • Mike Chaliy
    • Member since 09-14-2005, 8:34 AM
    • Ukraine
    • Posts 6

    Hello.

    I think I have solution for you. Please review my .Net 2.0 Updatable Xml DataSource. It is updatabale XmlDataSource implemenation. This mean that it support automatic inserting, updating and deleting. As bonus it supports paging and sorting.

  • Re: Error -System.NotSupportedException: Specified method is not supported.

    05-15-2006, 12:04 PM
    • Member
      130 point Member
    • sleekdigital
    • Member since 06-02-2003, 3:35 PM
    • Posts 28
    I will check out Mikes Updatable Xml DataSource control.  But I'd like the answer to this question as well.  I am handeling the RowUpdated event myself, but I still get the "Specified method is not supported" error.  Do I maybe need to also handle the RowUpdating event as well?  And what is this about ... "cancel the RowUpdate by setting the event argument's Cancel property to true".  I don't see any way of manipulating event arguments.  Please help us understand that better.  Thanks.
  • Re: Error -System.NotSupportedException: Specified method is not supported.

    10-05-2006, 3:06 PM
    • Member
      5 point Member
    • timbratcher
    • Member since 10-05-2006, 6:59 PM
    • Posts 1

    Protected Sub gv1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gv1.RowUpdating
        ' code for updating row manually goes here
    End Sub

    Protected Sub gv1_RowUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdatedEventArgs) Handles gv1.RowUpdated
        ' this prevents the error "Specified method is not supported." from being displayed.
        e.ExceptionHandled = True
    End Sub

    "cancel the RowUpdate by setting the event argument's Cancel property to true".

    I guess that should be something like "set the event's ExceptionHandled property to True."

  • Re: Error -System.NotSupportedException: Specified method is not supported.

    02-21-2007, 7:46 AM
    • Member
      6 point Member
    • TonyBlundell
    • Member since 02-21-2007, 12:38 PM
    • Sheffield, UK
    • Posts 8

    Hi all,


    I think there's a slightly simpler way of doing this...

     

    We must handle the RowUpdating event of the GridView, as the XMLDataSource doesn't fully support updating, so...

     

     

    Protected Sub gv1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles resourcesGridView.RowUpdating
    
    ' Your update code goes here.
    
    ' So the row doesn't display in edit mode...
    	resourcesGridView.EditIndex = -1
    ' Cancel the event, so the grid view doesn't try to make the data source do an auto update, and we avoid the 'method not supported error'...
    	e.Cancel = True
    
    End Sub
     
    Cheers,
    Tony 
     
     
  • Re: Error -System.NotSupportedException: Specified method is not supported.

    05-12-2008, 10:42 AM
    • Member
      2 point Member
    • Jeongwon
    • Member since 05-12-2008, 2:25 PM
    • Posts 1

    Hi

    I tried to use TemplateField instead using CommandField then it removed the error because it avoid calling method from XMLDataSource.

    This is my sample code. For CommandName  attribute, do not use "Edit", "Update" or "Cancel" because it will try to call specified method  from XMLDataSource and will give Error.

    <asp:TemplateField HeaderText = "Options">
             <ItemTemplate>
                     <asp:LinkButton ID="EditLinkButton" runat="server" Text="Edit" CommandName="EditCommand"></asp:LinkButton>
             </ItemTemplate>
             <EditItemTemplate>
                    <asp:LinkButton ID="UpdateLinkButton" runat="server" Text="Update" CommandName="UpdateCommand"></asp:LinkButton>
                    <asp:LinkButton ID="CancelLinkButton" runat="server" Text="Cancel" CommandName="CancelCommand"></asp:LinkButton>
            </EditItemTemplate>
    </asp:TemplateField>  

     

     

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
           
            LinkButton sourceLinkButton = (LinkButton)e.CommandSource;
            int rowIndex = ((GridViewRow)sourceLinkButton.Parent.Parent).RowIndex;

            if (e.CommandName == "EditCommand")
            {
                GridView1.EditIndex = rowIndex;
            }
            else if (e.CommandName == "UpdateCommand")
            {
                /* Update method will be here */
                GridView1.EditIndex = -1;
                GridView1.DataBind();
            }
            else if (e.CommandName == "CancelCommand")
            {
                GridView1.EditIndex = -1;
            }

    }

     


    Hope this help

    Jeongwon 

     

     

  • Re: Error -System.NotSupportedException: Specified method is not supported.

    08-08-2008, 5:14 PM
    • Member
      2 point Member
    • pluns
    • Member since 08-08-2008, 5:02 PM
    • Posts 1

    Gentle people,

    The following code fixed it for me:

    protected void GridView2_RowUpdated(object sender, GridViewUpdatedEventArgs e)
    {
           e.KeepInEditMode = false;
           e.ExceptionHandled =
    true;
    }

    protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
          
    // find entry in iatTable
          
    XmlDocument myXMLDoc = this.XmlDataSource2.GetXmlDocument();

           string sElemId = e.Keys[0].ToString();
          
    XmlNode selElement = myXMLDoc.GetElementById(sElemId);

           string sAttributeName = string.Empty;

           foreach(XmlNode attr in selElement.Attributes)
           {
               
    try
                {
                       sAttributeName = attr.Name.ToString();
                       selElement.Attributes[sAttributeName].Value = e.NewValues[sAttributeName].ToString();
                }
               
    catch
               
    {
                        // catch exceptions when Attribute cannot be written to ( e.g. Keys)
                        myTrace.Information(
    "No value to copy for: "+ sAttributeName);
                }
          
    }
          
    this.XmlDataSource2.Save();
          
    this.GridView2.DataBind();

           // e.Cancel = true;
    }

     

    ps. Great thread, helped me to find this solution

Page 1 of 1 (13 items)