Entries:
Comments:
Posts:

Loading User Information from Channel 9

Something went wrong getting user information from Channel 9

Latest Achievement:

Loading User Information from MSDN

Something went wrong getting user information from MSDN

Visual Studio Achievements

Latest Achievement:

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

DataBinding to a Web Service in ASP.NET 2.0

Download

Right click “Save as…”

One of the cool new features of ASP.NET 2.0 is its rich declarative databinding. In addition to traditional techniques like databinding to a back-end SQL database, you can also databind to web services, using the ObjectDataSource.

In this DevNugget, Mid-Atlantic .net Developer Evangelist G. Andrew Duthie (aka .net DEvHammer) shows you how you can very quickly create a web service to return structured data using a .net 2.0 DataSet class, then how you can easily bind your web service to an ASP.NET 2.0 GridView control using the ObjectDataSource, including both displaying and updating data.

Tags:

Follow the Discussion

  • Luciano Evaristo GuercheguercheLE guerchele

    Does DataGridView have an "Enable insert" option? I have not found such feature in DataGridView so far. Would you mind giving us directions to it?

    Kindly regards,

    Luciano Evaristo Guerche
    Taboao da Serra, SP, Brazil

  • G. Andrew Duthiegduthie Devhammer

    I'm not sure that there's a simple way to do that. Your best bet for inserts is to use something like the DetailsView control. You could add a DetailsView control to your page, along with an Add Row button or link, and only show the DetailsView when the Button/Link is displayed.

    I'm sure that you could customize the behavior of the GridView to allow inserts directly from the control, I'm just not sure it'd be worth the effort, compared to using the built-in DetailsView control.

  • guercheLE wrote:
    

    Does DataGridView have an "Enable insert" option? I have not found such feature in DataGridView so far. Would you mind giving us directions to it?

    Disclaimer: I haven't actually watched the video.

    That said, a GridView doesn't provide an configurable means of inserting new data, i.e. there is no "enable insert" option.  The GridView control does inherit the ability to support insert operations via an InsertCommand, much like a SelectCommand or DeleteCommand.  You must write this manually, though.  Furthermore, I found it necessary to create FooterTemplates to support this data entry and to create an EmptyDataTemplate to allow entry of initial items.

    So, as mentioned: it can be done, but I think there are easier ways to do what you want.

    Regards,
    Jim Greer
  • I have an application where I have a datagrid on a form, populated with data from a web service and I want to create relationships with mdf database tables within the same application.

    I am self teaching and sometimes it is very hard to grasp basic concepts. This video is more advanced than me, please can anyone guide me with the basic concept of how I can create relationships between a database table and a web service datagrid.

    Thanks

    stampcoverman
  • VOEVOE Vroom!
    Hi G. Andrew,

       Great information. I learned quite a bit. Even that this one will only run once. What am I to do with that <app settings for a dynamic port? Turn that feature off? Rebuild the web reference every time?

    This one was fun to learn from. I downloaded the swf file and ran it in Irfanview. I must of got a glitch in the transfer though as Irfanview locked up just about at the end of building the service provider. Flash players are cool though. I wish more control was avalible like in most video players, you know the slider? It did run okay in IE and Firefox.

       I saw the one on code snippets and started browsing the help files for more information on downloading them but it just gave me the run around. More on this would be cool because you use a screen cam not that I minded looking at Lisa. lol

    VOE(Visual Objects Environment) de KB9AGT signing off.Smiley


    P.S. I cannot run IIS on XP Home Edition.[C]
  • This is great! Smiley

    Finally, I have found what I needed. I have been searching all over the internet for binding a webservice to a datagrid.

    I am new to web services. And, I have definitely been doing things the hard way. So, I need to have the web service create a method where it is using the table adapter? This way I can choose an Object as my data source and then have it point to my web service? Does it matter that I am referencing a WSDL instead of asmx file?

    I have been choosing (none) as my data source and then binding the grid programmatically. I think the person who is providing me the WSDL is not sending me the correct web methods.

    Thanks.
  • Is it possible to use this method with some form of WSE3 security?  I'd like to be able to use a usernameTokenSecurity policy.  I know how to set the web service up with this but how do I get the consumer to supply the credentials?
  • How can i make this in c#?
  • thanks for the sample

    How i can changue the url of the webreference?
    changue the url in code or in config

    Thanks
  • VOEVOE Vroom!
    What? Take a look back at the Drag N Drop videos my friends. What was that button with the plus sign again? Hmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm?
  • VOEVOE Vroom!
    I thought this was about nuggets so he is using the wrong tool anyway. This must be the scrap pile.
  • This video seems to have problems.  I have tried it on two computers and I get "Media Failure...".  Has it been removed?

  • G. Andrew Duthiegduthie Devhammer

    Not sure why the video is not displaying properly in the embedded version. You can still access the WMV directly by clicking the WMV icon next to "Formats" below the embedded video...that seems to work fine. Sorry for the difficulty, I'll see if I can figure out what's up.

  • G. Andrew Duthiegduthie Devhammer

    Thanks to one of the kind folks on the Channel 9 team, we were able to isolate the issue and correct it. The video should work properly now.

     

    Andrew

  • Hi!

     

    First of all, great video,easy to follow, but something didn't work out for me:  everything works fine until I get to the Edit part.  

    *Note: I'm adapting your version to a school project, so I'm translating everything to C# and replacing Author with Players (database,names, etc.)

    *Note2: I'm pretty much a newbie

     

    When I'm writing the PlayersTA.Update part, it expects 7 arguments (my Players table has 7 fields), but when I run the code, click Edit, change a value, then click update, I get this message:  

    "ObjectDataSource 'PlayersDataSource' could not find a non-generic method 'UpdatePlayers' that has parameters: FirstName, Number, Description, BirthDate, LastName, Picture, Original_ID, ID."

     

    I'm not quite sure what the Original_ID field is, because the table doesn't contain it. If I try to write the Update code with 8 arguments, I can't even build it, because it says: No overload for method 'Update' takes '8' arguments.

     

    I also noticed that you have two au_id arguments in your code, but don't explain it. 

     

    I guess that the solution is quite simple, and maybe I gave you too many details, but I wanted to make sure that everything is clear Smiley

     

    Thanks in advance, 

    A

Remove this comment

Remove this thread

close

Comments Closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums,
or Contact Us and let us know.