• USA : +1 973 910 5725
  • INDIA: +91 905 291 3388
  • info@tekslate.com
  • Login

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.

ServiceMethod

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

Example

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’);

if(D)

D.populate(value);

}

</script>

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>

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

<asp:LinkButton — – – – –

– – – – –

</div>

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

<asp: LinkButton – – – – – –

– – – – – – –

</div>

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”>

</asp:DynamicpopulateExtender>

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);

Switch(contentkey)

{

case”1”;

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

break;

case”1”;

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

break;

 

}

Dataset Da=new .Dataset();

Da.Fill(DS);

Gridview GV=new GridView();

GV.Datasource=Ds.Tables[0];

GV.DataBind();

Stringwritter SW=new stringWriter();

HTML textwritter HTW=new HTML TextWriter(SW);

GV.RenderControl(HTW);

HTW.close();

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.

Summary
Review Date
Reviewed Item
Ajax Dynamic Populate Extender
Author Rating
5

“At TekSlate, we are trying to create high quality tutorials and articles, if you think any information is incorrect or want to add anything to the article, please feel free to get in touch with us at info@tekslate.com, we will update the article in 24 hours.”

0 Responses on Ajax Dynamic Populate Extender"

Leave a Message

Your email address will not be published. Required fields are marked *

Site Disclaimer, Copyright © 2016 - All Rights Reserved.