Ajax Dynamic Populate Extender

Dynamic Populate Extender

This control is used to populate a control available on the page dynamically with data.

It has following properties:

Target ControlID

used to specify ID of the control to extend.


used to specify the name of the method that will return the data to populate in the targetcontrol.


The following example populates a panel control with a gridview with data from the table based on the linkbutton on which user will click.

Add a page to the website and place a ToolKit ScriptManger on it.

Within HTMLsource of the page with in the headsection create a Javascript function with the name getdata as follows.

<script type=”text/javascript”>

function getdata(value)


var D =$find(‘Dynamic populateExtender1’);





With in HTML source of the page enclose each linkbutton in separate <div> tag & for that <div> tag in the ‘onlclick’ event call the javascript function getdata by setting the values 0, 1, & 2 respectively.

<div onlcick=”getdata(this.value) value=”0”>

<asp:LinkButton- - - - - - - - -

--- -- - - - - -


<div onclick =”getdata(this.value)” value=”1”>

<asp:LinkButton --- - - - -

- - - - -


<div onclick=”getdata(this.value)”value=”2”>

<asp: LinkButton - - - - - -

- - - - - - -


With in HTML source of the page take a Dynamic populate Extender and set following properties for it.

<asp:Dynamic populate Extender Id =”DynamicPopulateExtender1” runat=”server” TargetControlID=”panel1” ServiceMethod=”GetData”>


With in the Design of the page click on the smart tag ofpanel control and choose “add dynamic populate method “ that will create a method in the code with same name as the service method set for Dynamic populate method.

Public static string GetData(string contextKey)


sql connection cn=new sql connection(“server=Nikhil;database=mydb; uid=sa; pwd=123”);

SqlDataAdapte Da= new SqlDataAdapater(“Select*from EMP”,cn);




Da=new SqlDataAdapter(“Select * from dept”,cn);



Da=new SqlDataAdapter(“Select * from programmer”,cn);




Dataset Da=new .Dataset();


Gridview GV=new GridView();



Stringwritter SW=new stringWriter();

HTML textwritter HTW=new HTML TextWriter(SW);



return SW.Tostring();


At runtime when you click on the linkbutton caption employees it will get the data from EMP table ,When you click on LinkButton with the caption Departments,then it will get the data from Dept table and when you click on the LinkButton with the caption programmers, is will get the data from the programmers table and this data will be filles with in a GV and the GV will populate into the panel,Dynamically.