Ajax Dynamic Populate Extender

Ratings:
(4)
Views: 454
Banner-Img
Share this blog:

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.

You liked the article?

Like: 0

Vote for difficulty

Current difficulty (Avg): Medium

EasyMediumHardDifficultExpert
IMPROVE ARTICLEReport Issue

About Author

Authorlogo
Name
TekSlate
Author Bio

TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.

Stay Updated
Get stories of change makers and innovators from the startup ecosystem in your inbox