AjaxDataControls (ADC) FAQ - How to get started with the AjaxDataControls with Visual Studio 2005?

This is a quick how to post for everyone that would like to get started with the AjaxDataControls. I will cover all steps one by one to show you easy the controls can be used.

Open Visual Studio 2005 and create a new ASP.NET Ajax Enabled Website:

Add a reference to the AjaxDataControls.dll to your bin folder. You can download the binaries from here.

Once you have added the dll, we need to make some small changes to the web.config and add the following line between the <controls> section:

<add tagPrefix="AjaxData" namespace="AjaxDataControls" assembly="AjaxDataControls"/>

Your section should look like this now:

<pages>
  <controls>
    <add tagPrefix="asp" namespace="System.Web.UI" assembly="System.Web.Extensions, Version=1.0.61025.0, 
    Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add tagPrefix="AjaxData" namespace="AjaxDataControls" assembly="AjaxDataControls"/>
  </controls>
</pages>

If you want to return DataTables from your webservice or pageMethods you will also need to declare the following converters:

<jsonSerialization maxJsonLength="4194304">
  <converters>
    <add name="DataSetConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataSetConverter, Microsoft.Web.Preview"/>
    <add name="DataRowConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataRowConverter, Microsoft.Web.Preview"/>
    <add name="DataTableConverter" type="Microsoft.Web.Preview.Script.Serialization.Converters.DataTableConverter, Microsoft.Web.Preview"/>
  </converters>
</jsonSerialization>

Besides that you will need to download the ASP.NET Futures and add the binaries Microsoft.Web.Preview.dll to your website project.

This should go in between the <scripting>/<webServices> section.

You are now done with the web.config.

Now let us start with a simple webservice that will return some test data. Right click on the project and select "Add New Item" and select "Web Service" and give it the name DataService.asmx.

Open the DataService.vb and add the following namespace:

Imports System.Web.Script.Services
Imports System.Data

Replace this line:

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

with:

<ScriptService()> _

Add a test function that will return a DataTable with some test data:

<WebMethod()> _
Public Function TestData() As DataTable
  Dim dt As New DataTable("t1")
  dt.Columns.Add("image")
  dt.Columns.Add("title")

  For i As Integer = 0 To 10
    dt.Rows.Add(New Object() {"c:\img" & i.ToString() & ".jpg", "image-" & i.ToString()})
  Next

  Return dt
End Function

Open the default.aspx and drop an AjaxData Gridview into the page and give it the id MyGrid. By default it will autogenerate the columns for you based on your datasource. Next we need to set the webservice that we created earlier into the ScriptManager:

<asp:ScriptManager ID="ScriptManager1" runat="server">
  <Services>
    <asp:ServiceReference Path="~/DataService.asmx" />
  </Services>
</asp:ScriptManager>

Below the GridView markup add the following BLOCKED SCRIPT

<script type="text/javascript">
var _grid = null;
function pageLoad(sender, e)
{
  _grid = $find('<%= MyGrid.ClientID %>');
  DataService.TestData(onLoadSuccess);
}
       
function onLoadSuccess(result)
{
  _grid.set_dataSource(result.rows);
  _grid.dataBind();
}       
</script>

The first function is called automatically by the asp.net ajax framework whenever the page has loaded. In that function I retrieve an object of the Gridview control and store it into a local variable. Then I make a webservice call to the TestData function and pass the onLoadSuccess function to it, which will be called when the call has finished.

The onLoadSuccess takes the returned data sets the datasource via the set_dataSource function and binds the grid. Here is the result:

 

You can download the ADCSample Website from here.

Published Friday, June 13, 2008 11:52 PM by Sonu

Comments

# AjaxDataControls (ADC) FAQ - INDEX

Friday, June 13, 2008 11:04 PM by Sonu on .NET

Welcome to the AjaxDataControls FAQ. How to get started with the AjaxDataControls with Visual Studio

# Getting Started with the AjaxDataControls in Visual Studio 2005

Monday, June 16, 2008 11:37 AM by Jason N. Gaylord's Blog

Sonu Kapoor just posted about getting started with the AjaxDataControls in Visual Studio 2005 . The AjaxDataControls

# Getting Started with the AjaxDataControls in Visual Studio 2005

Monday, June 16, 2008 12:05 PM by ASPInsiders

Sonu Kapoor just posted about getting started with the AjaxDataControls in Visual Studio 2005 . The AjaxDataControls

# Getting Started with the AjaxDataControls in Visual Studio 2005

Monday, June 16, 2008 7:44 PM by Readed By Wrocław NUG members

Sonu Kapoor just posted about getting started with the AjaxDataControls in Visual Studio 2005 . The AjaxDataControls

# re: AjaxDataControls (ADC) FAQ - How to get started with the AjaxDataControls with Visual Studio 2005?

Friday, June 20, 2008 1:44 PM by xxxd

hello,

does the control work with vs 2008?

# re: AjaxDataControls (ADC) FAQ - How to get started with the AjaxDataControls with Visual Studio 2005?

Monday, June 23, 2008 10:20 AM by Sonu

Xun: To get this working with VS2008 - please download the VS2008 binaries from codeplex.com/ajaxdatacontrols. Also take a look at:

weblogs.asp.net/.../using-older-ajax-controls-in-visual-studio-2008.aspx

# AjaxDataControls (ADC) FAQ - How to get started with the AjaxDataControls and Visual Studio 2008?

Tuesday, June 24, 2008 12:21 AM by Sonu on .NET

This is a followup small how-to on my previous post: AjaxDataControls (ADC) FAQ - How to get started

# What is afraid of ADC? - Part I

Thursday, August 14, 2008 10:46 PM by Programmatically Speaking ...

ADC stands for AJAX Data Controls. It is one remarkable set of script data controls built with the Microsoft

# re: AjaxDataControls (ADC) FAQ - How to get started with the AjaxDataControls with Visual Studio 2005?

Sunday, September 26, 2010 11:47 PM by mohanms

Hi. Is there an example for VS2005 using C# language?

# re: AjaxDataControls (ADC) FAQ - How to get started with the AjaxDataControls with Visual Studio 2005?

Monday, September 27, 2010 9:35 PM by Sonu

No, I dont have any c# example. However there are plenty of converters out there, that can convert the code easily.