-->

Saturday, September 5, 2015

Add items to dropdownlist using TextBox in ASP.NET

In this article i will show you how to add items in DropdownList with value. In general way if we add items in the list then you can add only add Text in the list. Like
Dropdownlist1.Items.add(string Text);
But you want to add text with value from Textbox in Dropdownlist then check the below example:



Source

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        ENTER ITEMS :
        <asp:TextBox ID="TextBox1" runat="server" Width="209px"></asp:TextBox>
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="ADD ITEMS" />
        <br />
        <asp:DropDownList ID="DropDownList1" runat="server">
        </asp:DropDownList>
    </form>
 
     

</body>
</html>

Code Behind
 protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text.Trim()!="")
        {
            DropDownList1.Items.Add(new ListItem(TextBox1.Text, TextBox1.Text));
        }
    }

Friday, September 4, 2015

How to use WPF Ribbon with example

Ribbon Introduction

You know about ribbon, its a container of controls or text items like you ms-word menu bar. In MS-Word home tab contains lots of sub items like Text formatting, headings etc. These all things are possible through Ribbon in WPF.



In this video tutorial i will show you how to add reference to create ribbon in wpf. Using System.windows.controls.Ribbon namespace we can create a ribbon in WPF. Also show you how to add namespace for ribbon in xaml file. So lot of things i included in this video. 

Example of bind hyperlink in Datalist ASP.NET C#

Introduction
In this article i will show you how to take hyperlink control in datalist control also you can say how to bind hyperlink control into datalist. I will show you example of bind hyperlink control into datalist.
Datalist introduction
The Datalist control is a data bound control that displays data by using templates. These templates define controls and HTML elements that should be displayed for an item. The Datalist control exists within the System.Web.UI.WebControl namespace.



Some steps for binding Hyperlink control in Datalist

Step-1: Create a DataBase Table with  following fields.


Step-2: Fill this field with following values 

DepartmentID           Name                 Description
1                                  IT                     This is first department Name
2                                  CS                    This is Second Department Name


Step-3 : Create Procedure for retrieving values.

Database.mdf-->Stored Procedures -->Right click -->Add new Stored Procedure

CREATE PROCEDURE GetDepartments
AS
SELECT DepartmentID ,Name ,Description From [Table] ;

RETURN 0

Step-4: Take  a webform in your project name as "Departmentlist.aspx"
Step-5:  Paste this code into your Department.aspx





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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:DataList ID="DataList1" runat="server">
            <HeaderTemplate>
                Choose a Department
            </HeaderTemplate>
            <ItemTemplate>
                <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl ='<%#Link .ToDepartment (Eval ("DepartmentID").ToString ()) %>'
                  Text ='<%# HttpUtility .HtmlEncode (Eval ("Name").ToString ()) %>' ToolTip ='<%# HttpUtility .HtmlEncode (Eval ("Description").ToString ()) %>'   >

                </asp:HyperLink>
            </ItemTemplate>
        </asp:DataList>
    <div>
    
    </div>
    </form>
</body>
</html>

Step-6: Paste this code into your codebehind file


using System;
using System.Data.SqlClient;
using System.Data;


public partial class Departmentlist : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection();
        con.ConnectionString = @"Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True";
            con.Open ();
        SqlCommand cmd=new SqlCommand ();
        cmd.CommandText ="GetDepartments";
        cmd.CommandType =CommandType .StoredProcedure ;
        cmd.Connection =con;
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        da.Fill(ds, "Department");
        DataList1.DataSource = ds;
        DataList1.DataBind();



    }
}

Step-7 Make a Link class for absolute url


using System;
using System.Web;

/// <summary>
/// Summary description for Link
/// </summary>
public class Link
{
    public static string BuildAbsolute(string relativeuri)
    {
        // get current uri
        Uri uri = HttpContext.Current.Request.Url;
        // build absolute path
        string app = HttpContext.Current.Request.ApplicationPath;
        if (!app.EndsWith("/"))
               
            app += "/";
        relativeuri = relativeuri.TrimStart('/');
        // return the absolute path
        return HttpUtility .UrlPathEncode (String .Format ("http://{0}:{1}{2}",uri .Host ,uri.Port ,app ));

 

    }
    public static string ToDepartment(string departmentId, string page)
    {
        if (page == "1")
     
            return BuildAbsolute(string.Format("catalog.aspx?DepartmentID={0}", departmentId));
        else
            return BuildAbsolute (string .Format ("catalog.aspx?DepartmentID={0}&Page={1}",departmentId,page ));
           

    }
    //generate a department url for the first page
    public static string ToDepartment(string departmentId)
    {
        return ToDepartment(departmentId, "1");
    }

 
}


Out Put 

Thursday, September 3, 2015

How to show popup on page load using JQuery

Introduction
In this article i will show you how a popup window appears with some controls or text message when first or each time window load . I will give you an example of modal pop window on page load.  .

Description 
In previous article i explained how to show modal pop using JQuery. Here we use same article for modal popup but something change in JQuery function. In this article i will use ready( ) function of document object. In JQuery, if you want to execute some functions and operations on page load then use $(document).ready (function here).


Source Code


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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
      <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.js" ></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js" ></script>

    <script>

        $(function () {
            $(document).ready(function () {

                $('#popup').dialog({
                    title: "JQuery popup model",
                    width: 450,
                    height: 250,
                    modal: true,
                    button: {
                        close: function () {
                            $(this).dialog('close');

                        }
                    }

                });
            });


        })
    </script>





</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div id="popup" title="page load modal popup" style="display:none">
            <b>Today News:</b>
            Currently launched windows 10 professional version

        </div>
 
    </div>
    </form>
</body>
</html>


Code Generate the following output

How to show popup on page load using JQuery


How to show login form in modal popup window in ASP.NET

Introduction
In this article i will show you how a login form appear in modal popup. I will give you an example of modal pop with login or register control. When we click on login button then modal popup appears with login form , now user can login from this window.

Description 
In previous article i explained how to show modal pop using JQuery. Here we use same article for modal popup but something change in division.

Source Code


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

<%@ Register Src="~/logincontrol.ascx" TagPrefix="uc1" TagName="logincontrol" %>


<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">

    <title></title>
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.js"></script>
     <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
    <script>

        $(function () {
            $('#Button1').click(function () {

                $('#popup').dialog({

                    title: "Login Control",
                    width: 500,
                    height: 500,
                    modal: true,
                    buttons: {
                        close: function () {
                            $(this).dialog('close');
                        }
                    }


                });


            });

        })

    </script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div id="popup" title="Login Form" style="display:none">
     
     UserName: <input id="Text1" type="text" /> <br />
Password: <input id="Text2" type="text" /> <br />
        <input id="loginbtn" type="button" value="Login" />

    </div>
        <input id="Button1" type="button" value="click to login" />
    </div>
    </form>
</body>
</html>

Code Generate the following output

How to show login form in modal popup window in ASP.NET


Wednesday, September 2, 2015

Example of simple modal Popup window in JQuery

Introduction 
In this article i will show you how to show a dialog box when we click on button. I will show you a example of modal window using JQuery in ASP.NET. You can use this concept in every language.

Description

In previous article i explained Textbox takes only numeric value,  Example of Text ZoomIn and ZoomOut in Jquery.

Code of modal window

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
    <script src="http://code.jquery.com/jquery-1.8.2.js" ></script>
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js" ></script>
    <script>

        $(function () {
            $('#buttonclick').click(function () {

                $('#popup').dialog({
                    title: "JQuery popup model",
                    width: 450,
                    height: 250,
                    modal: true,
                    button: {
                        close: function () {
                            $(this).dialog('close');

                        }
                    }

                });
            });


        })


    </script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <div id="popup" title="Model PopUp" style="display:none">
        <b>Welcome to dotprogramming.blogspot.com</b>

    </div>
        <input type="button" id="buttonclick" value="Show Model" />
    </div>
    </form>
</body>
</html>
Code generate the following output



Tuesday, September 1, 2015

Example of ConfirmButtonExtender control of ajax in ASP.NET

Introduction

In this article i will show you how to popup confirmation dialog box using ASP.NET C#. Also you can say example of Confirmation dialog box in asp.net. This thing is possible by two ways first one, you can use AJAX ConfirmButtonExtender and second one is JavaScript. I will show you how to use ConfirmButtonExtender of ajax in asp.net

You can check this video to do this things by two ways




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

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
 
        <br />
 
        <asp:Button ID="Button1" runat="server" Text="Delete Record" />
 
        <cc1:ConfirmButtonExtender ID="Button1_ConfirmButtonExtender" runat="server" BehaviorID="Button1_ConfirmButtonExtender" ConfirmText="Are you sure you want to delete it" TargetControlID="Button1" />
 
    </div>
    </form>
</body>
</html>
© Copyright 2013 Computer Programming | All Right Reserved