Blue Theme Orange Theme Green Theme Red Theme
 
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

Binding ajax popup extender with database value.

 by Abhijit barua on Jan 24, 2012

Binding ajax popup extender with database value using web service and stringbuilder.
Download Files: Binding ajax poup extender with database value..ra
Comments: 0 Views: 1237 Printable Version 

Today I want to show how you can bind one ajax popup extender control with database value using web service and stringbuilder. Suupose you have one database table with newsid,headlines,entrydate,news. You want to show in gridview,datalist or repeater and when someone want to read details news then popup will show like below.

(image you will get at attach file).


Fist I take gridview like below.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"

                        AllowPaging="True" PageSize="5"

                        onpageindexchanging="GridView1_PageIndexChanging">

                        <Columns>

                            <asp:BoundField DataField="id" HeaderText="NEWS ID" />

                            <asp:BoundField DataField="headlines" HeaderText="HEADLINES" />

                            <asp:BoundField DataField="DOE" HeaderText="ENTRY DATE" />

                           <asp:TemplateField ItemStyle-Width="40" ItemStyle-HorizontalAlign="Right">

         <ItemTemplate>

 

            <asp:Image ID="Image1" runat="server" ImageUrl="~/image/Comment_edit.png" />

 

            <asp:PopupControlExtender ID="PopupControlExtender1" runat="server"

               PopupControlID="Panel1"

               TargetControlID="Image1"

               DynamicContextKey='<%# Eval("id") %>'

               DynamicControlID="Panel1"

               DynamicServiceMethod="GetDynamicContent" Position="Bottom">

            </asp:PopupControlExtender>

           

           

         </ItemTemplate>

 

      </asp:TemplateField>

                        </Columns>

                    </asp:GridView>

<asp:Panel ID="Panel1" runat="server"> </asp:Panel>

Note:-Please download Comment_edit.png image and put in image folder.

Here I take one image control and at TargetControlID of poup extender I give image control id. Below gridview you can see one panel which id I put at PopupControlID.Now your ajax page is set.

DynamicContextKey='<%# Eval("id") %>'

DynamicControlID="Panel1"

DynamicServiceMethod="GetDynamicContent" Position="Bottom"

Let's see below lines of poup extender carefully. At DynamicContextKey you will have to put the id through which news will search. DynamicControlID I put panel1 where everytime news will show and at DynamicServiceMethod I put GetDynamicContent webservice name which I write at server side. Server side code I write like below.

 

    [System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]

    public static string GetDynamicContent1(string contextKey)

    {

        string constr = "Data Source=server name;Initial Catalog=DB name;Integrated Security=True;";

        string query = "SELECT imgpath FROM img_table WHERE imgid = " + contextKey;

 

        SqlDataAdapter da = new SqlDataAdapter(query, constr);

        DataTable table = new DataTable();

 

        da.Fill(table);

 

        StringBuilder b = new StringBuilder();

 

        b.Append("<table style='background-color:#f3f3f3; border: #336699 3px solid; ");

        b.Append("width:350px; font-size:10pt; font-family:Verdana;' cellspacing='0' cellpadding='3'>");

 

        b.Append("<tr><td colspan='3' style='background-color:#336699; color:white;'>");

        b.Append("<b>NEWS DETAILS</b>"); b.Append("</td></tr>");

        b.Append("<tr><td style='width:80px;'><b>imgpath</b></td>");

 

 

        b.Append("<tr>");

        b.Append("<td>" + table.Rows[0]["imgpath"].ToString() + "</td>");

        b.Append("</tr>");

        b.Append("</table>");

 

        return b.ToString();

    }

protected void Page_Load(object sender, EventArgs e)

    {

       

    }

Happy codding.

 

 

 

 

 

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 
Comments not available.
Team Foundation Server Hosting
Become a Sponsor

 Blogger's Profile
Age: 30
Location:
Title: Developer
Joined: Nov 18, 2011
Education: Masters Degree
 More Blogs from this Blogger
No record available
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 

 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.