Breaking News

Editors Picks

Thursday, July 15, 2010

Model Popup with Datalist in Link Button in asp.net using Ajax






Code For Default.aspx Page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
    <style type="text/css">
        TR.updated TD
        {
            background-color: #084067;
        }
        .modalBackground
        {
            background-color: Gray;
            filter: alpha(opacity=70);
            opacity: 0.7;
        }
        .linkb
        {
            background-image: url(images/btnsms.png);
        }
        .linkb1
        {
            background-image: url(images/btnEmail.png);
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <asp:DataList ID="DataList1" runat="server" DataSourceID="" OnItemCommand="DataList1_ItemCommand"
            OnItemDataBound="DataList1_ItemDataBound" Width="267px">
            <HeaderTemplate>
            </HeaderTemplate>
            <ItemTemplate>
                <table>
                    <tr>
                        <td>
                            <asp:Image ID="Image1" runat="server" ImageUrl='<%# DataBinder.Eval(Container.DataItem, "image_path") %>' />
                        </td>
                    </tr>
                    <tr>
                        <td>
                            '<%# DataBinder.Eval(Container.DataItem, "status") %>'
                        </td>
                    </tr>
                    <tr>
                        <td>

  /* Modelpopup when click on This 
Link Button
 */
                   



<asp:LinkButton ID="LnkDetails" Text="Details" runat="server" CommandName="popup"

                                CommandArgument='<%# DataBinder.Eval(Container.DataItem, "tourist_place_id ").ToString() %>'

                                CausesValidation="false" />
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:DataList>
        <asp:ModalPopupExtender ID="MPE" runat="server" BackgroundCssClass="modalBackground"
            TargetControlID="btnDummy" EnableViewState="true" PopupControlID="Panel1" OkControlID="Button1"
            CancelControlID="Button3">
        </asp:ModalPopupExtender>
        <div style="display: none">
            <asp:Button ID="btnDummy" runat="server" Text="Button" />
        </div>
        <asp:Panel ID="Panel1" runat="server" BorderColor="Green" Style="display: none" BorderWidth="2px"
            BackColor="Aqua" Width="250px" Height="250px">
            <asp:GridView ID="GridView1" runat="server">
            </asp:GridView>
            <asp:Button ID="Button1" runat="server" Text="OK" />
            <asp:Button ID="Button3" runat="server" Text="Cancel" />
        </asp:Panel>
    </div>
    </form>
</body>
</html>

Code For 

Default2.aspx.cs Page 



using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Default2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection("server=.; database=Encyclopedia;integrated security=true");
        SqlDataAdapter da = new SqlDataAdapter("select * from dbo.photo_gallery", con);
        DataTable dt = new DataTable();
        da.Fill(dt);
        DataList1.DataSource = dt;
        DataList1.DataBind();
    }
    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
    {
        string detain_id = e.CommandArgument.ToString();
        SqlConnection con1 = new SqlConnection("server=.; database=Encyclopedia;integrated security=true");
        SqlDataAdapter da1 = new SqlDataAdapter("select * from dbo.photo_gallery where tourist_place_id="+ detain_id + "", con1);
        DataTable dt1 = new DataTable();
        da1.Fill(dt1);
        GridView1.DataSource = dt1;
        GridView1.DataBind();
        
        if (e.CommandName == "popup")
        {

            MPE.Show();

        }
    }

    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
       

    }
}





Read more ...

Contact Us

Name

Email *

Message *