Asp.net C# Code

Asp.net c# code and sql server database examples.

Asp.net C#

1. popbox open from server side click button c#.?



click preview button...




















Ans. DataListPOPBOX.aspx code



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



<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<!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 id="Head1" runat="server">

    <title></title>

    <style type="text/css">

        html, html a

        {

            -webkit-font-smoothing: antialiased;

            text-shadow: 1px 1px 1px rgba(0,0,0,0.004);

        }

     

        body

        {

            font-family: 'Open Sans' , sans-serif;

            background: #e2e2e2;

        }

     

        #plans, #plans ul, #plans ul li

        {

            margin: 0;

            padding: 0;

            list-style: none;

        }

     

        #pricePlans:after

        {

            content: '';

            display: table;

            clear: both;

        }

     

        #pricePlans

        {

            zoom: 1;

        }

     

        #pricePlans

        {

            max-width: 69em;

            margin: 0 auto;

        }

     

        #pricePlans #plans .plan

        {

            background: #fff;

            float: left;

            width: 100%;

            text-align: center;

            border-radius: 5px;

            margin: 0 0 20px 0;

            -webkit-box-shadow: 0 1px 3px rgba(0,0,0,0.1);

            box-shadow: 0 1px 3px rgba(0,0,0,0.1);

        }

     

        .planContainer .title h2

        {

            font-size: 2.125em;

            font-weight: 300;

            color: #3e4f6a;

            margin: 0;

            padding: .6em 0;

        }

     

        .planContainer .title h2.bestPlanTitle

        {

            background: #3e4f6a;

            background: -webkit-linear-gradient(top, #475975, #364761);

            background: -moz-linear-gradient(top, #475975, #364761);

            background: -o-linear-gradient(top, #475975, #364761);

            background: -ms-linear-gradient(top, #475975, #364761);

            background: linear-gradient(top, #475975, #364761);

            color: #fff;

            border-radius: 5px 5px 0 0;

        }

     

     

        .planContainer .price p

        {

            background: #3e4f6a;

            background: -webkit-linear-gradient(top, #475975, #364761);

            background: -moz-linear-gradient(top, #475975, #364761);

            background: -o-linear-gradient(top, #475975, #364761);

            background: -ms-linear-gradient(top, #475975, #364761);

            background: linear-gradient(top, #475975, #364761);

            color: #fff;

            font-size: 1.2em;

            font-weight: 700;

            height: 2.6em;

            line-height: 2.6em;

            margin: 0 0 1em;

        }

     

        .planContainer .price p.bestPlanPrice

        {

            background: #f7814d;

        }

     

        .planContainer .price p span

        {

            color: #8394ae;

        }

     

        .planContainer .options

        {

            margin-top: 10em;

        }

     

        .planContainer .options li

        {

            font-weight: 700;

            color: #364762;

            line-height: 2.5;

        }

     

        .planContainer .options li span

        {

            font-weight: 400;

            color: #979797;

        }

     

        .planContainer .button a

        {

            text-transform: uppercase;

            text-decoration: none;

            color: #3e4f6a;

            font-weight: 700;

            letter-spacing: 3px;

            line-height: 2.8em;

            border: 2px solid #3e4f6a;

            display: inline-block;

            width: 80%;

            height: 2.8em;

            border-radius: 4px;

            margin: 1.5em 0 1.8em;

        }

     

        .planContainer .button a.bestPlanButton

        {

            color: #fff;

            background: #f7814d;

            border: 2px solid #f7814d;

        }

     

        #credits

        {

            text-align: center;

            font-size: .8em;

            font-style: italic;

            color: #777;

        }

     

        #credits a

        {

            color: #333;

        }

     

        #credits a:hover

        {

            text-decoration: none;

        }

     

        @media screen and (min-width: 481px) and (max-width: 768px)

        {

     

            #pricePlans #plans .plan

            {

                width: 49%;

                margin: 0 2% 20px 0;

            }

     

            #pricePlans #plans > li:nth-child(2n)

            {

                margin-right: 0;

            }

     

        }

     

        @media screen and (min-width: 769px) and (max-width: 1024px)

        {

     

            #pricePlans #plans .plan

            {

                width: 49%;

                margin: 0 2% 20px 0;

            }

     

            #pricePlans #plans > li:nth-child(2n)

            {

                margin-right: 0;

            }

     

        }

     

        @media screen and (min-width: 1025px)

        {

     

            #pricePlans

            {

                margin: 2em auto;

            }

     

            #pricePlans #plans .plan

            {

                width: on:;

                margin: 0 1.33% 20px 0;

                -webkit-transition: all .25s;

                -moz-transition: all .25s;

                -ms-transition: all .25s;

                -o-transition: all .25s;

                transition: all .25s;

            }

     

            #pricePlans #plans > li:last-child

            {

                margin-right: 0;

            }

     

            #pricePlans #plans .plan:hover

            {

                -webkit-transform: scale(1.04);

                -moz-transform: scale(1.04);

                -ms-transform: scale(1.04);

                -o-transform: scale(1.04);

                transform: scale(1.04);

            }

     

            .planContainer .button a

            {

                -webkit-transition: all .25s;

                -moz-transition: all .25s;

                -ms-transition: all .25s;

                -o-transition: all .25s;

                transition: all .25s;

            }

     

            .planContainer .button a:hover

            {

                background: #3e4f6a;

                color: #fff;

            }

     

            .planContainer .button a.bestPlanButton:hover

            {

                background: #ff9c70;

                border: 2px solid #ff9c70;

            }

     

        }

     

        /*pop css start*/

     

        .modalBackground

        {

            background-color: Black;

            filter: alpha(opacity=90);

            opacity: 0.8;

        }

        .modalPopup

        {

            background-color: #FFFFFF;

            border-width: 3px;

            border-style: solid;

            border-color: black;

            padding: 12px 44px 17px 45px; /* padding-top: 10px;

        padding-left: 10px;

        /*width: 300px;*/

            width: auto; /*height: 140px;*/

            height: auto;

        }

     

     

        /*pop css end*/

    </style>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:ScriptManager ID="ScriptManager1" runat="server">

        </asp:ScriptManager>

        <%--Start shipping Bag--%>

        <asp:HyperLink ID="lnkbag" runat="server" Text="My Shipping Bag" NavigateUrl="~/User Site Code/shopingbag.aspx"></asp:HyperLink>

        (<asp:Label ID="lblbag" runat="server" Text="0"></asp:Label>)

        <%--End shipping Bag--%>

        <div style="text-align: center; color: Black; height: 30px; width: auto; text-transform: uppercase;

            font-size: large; background-color: White;">

            Ring Products</div>

        <asp:DataList ID="DataList1" runat="server" Font-Names="Verdana" Font-Size="Small"

            RepeatColumns="6" RepeatDirection="Horizontal" Visible="True" OnItemCommand="itemcommand"

            Height="16px">

            <ItemStyle ForeColor="Black" />

            <ItemTemplate>

                <div id="pricePlans">

                    <ul id="plans">

                        <li class="plan">

                            <ul class="planContainer">

                                <li class="title">

                                    <h2>

                                        <asp:Label ID="lbl_IDPASS" runat="Server" Text='<%# Eval("EmployeeID") %>'></asp:Label>

                                    </h2>

                                </li>

                                <li class="title">

                                    <asp:LinkButton ID="lnk1" runat="server" CommandName='<%#Eval("PhotoPath") %>'>

                                        <asp:Image ID="img" runat="server" Width="200px" Height="189px" ImageUrl='<%#Eval("PhotoPath")%>' />

                                    </asp:LinkButton>

                                </li>

                                <li>

                                    <ul class="options">

                                        <li><span>

                                            <asp:CheckBox ID="chkboxselect" runat="server" />

                                        </span></li>

                                        <li><span>

                                            <asp:Label ID="Label1" runat="server" Text="Sale Price :- $"></asp:Label>

                                            <asp:Label ID="lblCity" runat="server" Text=' <%# Bind("PostalCode") %>'></asp:Label>

                                        </span></li>

                                        <li><span>

                                            <asp:Label ID="lblCountry" runat="server" Text='<%# Bind("Country") %>'></asp:Label>

                                        </span></li>

                                    </ul>

                                </li>

                                <li class="button">

                                    <asp:LinkButton ID="lnkbtnpreview" runat="server" OnClick="LinkButton1_Click">Preview</asp:LinkButton>

                                </li>

                            </ul>

                        </li>

                    </ul>

                </div>

                <!-- ModalPopupExtender -->

                <cc1:ModalPopupExtender ID="mp1" runat="server" PopupControlID="Panel1" TargetControlID="lnkbtnpreview"

                    CancelControlID="btnClose" BackgroundCssClass="modalBackground" DropShadow="true">

                </cc1:ModalPopupExtender>

                <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" align="center" Style="display:none">

                    <table id="tblpopbox">

                        <tr>

                            <td colspan="2" style="border-bottom-style: groove; border-bottom-width: thin; border-bottom-color: #666633">

                                <asp:Label ID="lbltitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label>

                            </td>

                            <td align="right" style="border-bottom-style: groove; border-bottom-width: thin;

                                border-bottom-color: #666633">

                                <asp:ImageButton ID="btnClose" runat="server" AlternateText="Button" ImageUrl="~/CheckBox_Image/close.png" />

                            </td>

                        </tr>

                        <tr>

                            <td rowspan="8">

                                <img src="<%# Eval("PhotoPath")%>" width="200px" height="189px" />

                            </td>

                            <td>

                                Item Code :-

                            </td>

                            <td>

                                <asp:Label ID="lblItemCode" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label>

                            </td>

                        </tr>

                        <tr>

                            <td>

                                Sale Price :-

                            </td>

                            <td>

                                <asp:Label ID="lblSalePrice" runat="server" Text='<%# Bind("Title") %>'></asp:Label>

                            </td>

                        </tr>

                        <tr>

                            <td>

                                Dimension :-

                            </td>

                            <td>

                                <asp:Label ID="lblDimension" runat="server" Text='<%# Bind("PostalCode") %>'></asp:Label>

                            </td>

                        </tr>

                        <tr>

                            <td>

                                Available Size

                            </td>

                            <td>

                                <asp:Label ID="lblAviSize" runat="server" Text='<%# Bind("Country") %>'></asp:Label>

                            </td>

                        </tr>

                        <tr>

                            <td>

                                Weight

                            </td>

                            <td>

                                <asp:Label ID="lblweight" runat="server" Text='<%# Bind("PostalCode") %>'></asp:Label>

                            </td>

                        </tr>

                        <tr>

                            <td>

                                Color

                            </td>

                            <td>

                                <asp:Label ID="lblcolor" runat="server" Text='<%# Bind("TitleofCourtesy") %>'></asp:Label>

                            </td>

                        </tr>

                        <tr>

                            <td>

                                Metal

                            </td>

                            <td>

                                <asp:Label ID="lblmetal" runat="server" Text='<%# Bind("Address") %>'></asp:Label>

                            </td>

                        </tr>

                        <tr>

                            <td>

                                Stock Qty

                            </td>

                            <td>

                                <asp:Label ID="lblstockqty" runat="server" Text='<%# Bind("HomePhone") %>'></asp:Label>

                            </td>

                        </tr>

                        <tr>

                            <td>

                            </td>

                            <td>

                            </td>

                            <td>

                            </td>

                        </tr>

                        <tr>

                            <td align="Centor">

                                <td>

                                    <asp:ImageButton ID="btnAddToCart" runat="server" AlternateText="Button" ImageUrl="~/CheckBox_Image/addcart.jpg"

                                        OnClick="btnAddToCart_Click" CommandName='<%#Eval("PhotoPath") %>' />

                                </td>

                                <td>

                                    <asp:ImageButton ID="btnADDToWishlist" runat="server" AlternateText="Button" ImageUrl="~/CheckBox_Image/wishlist.png" />

                                </td>

                        </tr>

                    </table>

                </asp:Panel>

                <!-- ModalPopupExtender -->

            </ItemTemplate>

        </asp:DataList>

    </div>

    <%--    second--%>

    <div>

    </div>

    </form>

</body>

</html>







DataListPOPBOX.aspx.cs code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.IO;
using System.Collections;
using System.Windows.Forms;
using System.Windows;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class DataListPOPBOX : System.Web.UI.Page
{
    SqlConnection connn = new SqlConnection("Data Source=SONU-PC\\SQLEXPRESS; Initial Catalog=NORTHWND;Integrated Security=true;");
    
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //call function
            DataListBind();
           
        }
    }
    //All product datalist bind
    public void DataListBind()
    {


        connn.Open();
        SqlCommand cmd = connn.CreateCommand();
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = "select * from Employees where City='London'";
        cmd.ExecuteNonQuery();
        DataTable dt = new DataTable();
        SqlDataAdapter sda = new SqlDataAdapter(cmd);
        sda.Fill(dt);
        DataList1.DataSource = dt;
        DataList1.DataBind();
        
        connn.Close();

        //
        //SqlCommand cmddd = new SqlCommand("select * from Employees where City='London' ", connn);
        //DataSet ds = new DataSet();
        //DataTable dt = new DataTable();
        //SqlDataAdapter da = new SqlDataAdapter(cmddd);
        //da.Fill(ds);
        //DataList1.DataSource = ds.Tables[0];
        //DataList1.DataBind();

       



    }
   
    protected void itemcommand(object source, DataListCommandEventArgs e)
    {
        //int i;
        if (e.CommandName !=null)
        //if (e.CommandName == "SHW")
        {

            
            int counter = int.Parse(lblbag.Text);
            counter++;
            lblbag.Text = counter.ToString();
            Session["bagses"] = lblbag.Text;

           // Response.Redirect("ZoomCODE.aspx");
            //Response.Redirect("www.google.com");
            //i = e.Item.ItemIndex;
            
           // Label l = (Label)DataList1.Items[i].FindControl("PostalCode");
            //lblbag.Text = l.ToString();
            //Session["name"] = l;
            //string name = lblbag.Text.Trim();
            //Session["name"] = name;

            //

            DataListItem row = DataList1.Items[e.Item.ItemIndex];
            
            
            
                //DropDownList ddlTitle = (DropDownList)row.FindControl("PD_TitleLabel");
                Label lblFirstName = (Label)row.FindControl("lbl_IDPASS");
                //Label lblLastName = (Label)row.FindControl("PD_LastNameLabel");
                string s_uniqueid = lblFirstName.Text;

                //Session["title"] = lblFirstName.Text;
                Session.Add("title", s_uniqueid);
                //Session["firstname"] = lblFirstName.Text;
                //Session["lastname"] = lblLastName.Text;

                //Response.Redirect("ZoomCODE.aspx?ID="+lblFirstName.Text); 
           
        }

    }

    protected void LinkButton1_Click(object sender, EventArgs e)
    {
        Response.Redirect("ZoomCODE.aspx?ID="); 
       
    }


    protected void btnAddToCart_Click(object sender, ImageClickEventArgs e)
    {
        //if (e.CommandName == "AddtoCart")
        //{
        //    DataListItem row = DataList1.Items[e.Item.ItemIndex];
        //    Label lblFirstName = (Label)row.FindControl("lbl_IDPASS");
        //    string a = l1.Text;
        //    Response.Write(l1.Text);       
        //}
        //if(Session["LogedIn"] !=null)
        // {
        //    //values = new object[GridView1.Rows[0].Cells.Count];
        //    //for(int i=0; i< GridView1.rows[0].cells.count;i++)
        //    //{
        //    //    values[i]=GridView1.Rows.[0].cells[i].text;
        //    //}
        //    //cartTable=(DataTable)Session["cartDetails"];
        //    //cartTable.Rows.Add(values);
        //    //Session["cartDetails"]=cartTable;
        //    //addToCart.Enabled=false;
        //}
        //else
        //{
        //    Response.Redirect("Login.aspx");
        //}
    }
}


Thank You...