-->

Thursday, October 1, 2015

WPF: Show Each row details in DataGrid when we click on rows

Introduction
In this article i will explain how to bind the DataGrid with list, which is already bind with public class. Also explain, when we click on any row of DataGrid then it display detailed information of selected row. This things is possible through RowDetailsTemplate of DataGrid Template. In this DataGrid we have two TextColumn and one TextBlock.

Source Code

<Grid Name="grid1" Margin="0,10,0,0">
        <DataGrid Name="dg" AutoGenerateColumns="False">
            <DataGrid.Columns>
                <DataGridTextColumn Header="ID" Binding="{Binding Id}"/>
                <DataGridTextColumn Header="Name" Binding="{Binding Name}"/>


            </DataGrid.Columns>
            <DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <TextBlock Text="{Binding Details}"/>
                </DataTemplate>
            </DataGrid.RowDetailsTemplate>          
        </DataGrid>    

    </Grid>

Code Behind 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for addcolumn.xaml
    /// </summary>
    public partial class addcolumn : Window
    {
        public addcolumn()
        {
            InitializeComponent();
            List<student> students = new List<student>();
            students.Add(new student() { Id = 1, Name = "Jacob" });
            students.Add(new student() { Id = 2, Name = "Bill" });
            students.Add(new student() { Id = 3, Name = "Ammey" });
            students.Add(new student() { Id = 4, Name = "John" });
            students.Add(new student() { Id = 5, Name = "kitty" });
            dg.ItemsSource = students;
       
        }
     public class student
     {
         public int Id { get; set; }
         public string Name { get; set; }
         public string Details
         {
             get
             {
                 return String.Format("{0}=>this is row id and {1}=> this is row name", Id, Name);
             }
         }
     }
           
    }
}

Code generate the following output

WPF: Show Each row details in DataGrid when we click on rows

Wednesday, September 30, 2015

fire event inside another event using JQuery

Introduction
In this article i will show you how to fire event inside event using JQuery. I will give an example of it. In this article, first we create a table using JQuery then append the table with the dynamically created table. First, we get the column of the table for inside event then generate function on table row. Lets check the example.

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <title></title>
    <script>
 

        $(function () {
            $("#btncreate").click(function () {
                var newtable = '<table id="mytable"><tr><td>Column1</td><td>Column2</td></tr><tr><td>Row11</td><td>Row12</td></tr></table>';
                $("#tbcontainer").append(newtable);

                var tblid = $("#tbcontainer table").attr("id");
           
                $("#" + tblid).on("click", "tr:last", function () {
                    var val1 = $(this).find("td").eq(0).text();
                    var val2 = $(this).find("td").eq(1).text();
                    alert(val1 + "  " + val2);
                })
            })
        })
</script>

</head>
<body>
    <form id="form1" runat="server">
    <div>
    <label id="tbcontainer" />
   
        <input id="btncreate" type="button" value="button" />
    </div>
    </form>
</body>
</html>

Code Generate the following output
fire event inside another event using JQuery

Open and close new window using JQuery

Introduction
In this article i will show you how to open new window when we click on button using JQuery. I will give an example of it. Also do some thing like when we click on other button then opened new window will closed also mentioned in the example.

Description
I have explained Get browser details using JQuery, Button work as fileupload control in JQuery.
Source code
<!DOCTYPE html>
<html>
<head>
    <title> OPen and close window using JQuery </title>
</head>
<body>

    <form name="form1">
        <input type="button" value="Open New Window" id="btnOpen" />
        <p> <input type="button" value="Close New Window" id="btnClose" />

    </form>
    <script src="https://code.jquery.com/jquery-2.1.4.js"></script>
    <script type="text/javascript">
     
        var Window1;
        $(function () {
            $(form1.btnOpen).click(function () {
                Window1 =  window.open('', 'YourWindow', 'height=500,width=500');
            });
            $(form1.btnClose).click(function () {
                Window1.close();
            });
        });

   
 
    </script>
</body>
</html>
Code Generate the following output
Open and close new window using JQuery

Tuesday, September 29, 2015

Get browser details using JQuery

Introduction 
In this article i will show you how to determine which web browser is selected for your application or you can say that how many user open your website in which web browser. Through this article i will show you Browser type, Browser version etc. Lets check the example of getting browser details using JQuery.



Description
In previous article i explained Button work as fileupload control in JQuery  , Select box validation using JQuery , JQuery TextBox validation when it emptyRetrieve selected Radio button and checkbox value using JQueryHow to show popup on page load using JQuery .

Code Example:

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
    <script src="http://code.jquery.com/jquery-migrate-1.2.1.js"></script>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <label id="blbl" />
        <script>
            $(function () {

                $.each($.browser, function (i, val) {

                    $("#blbl").append(i + '=>' + val + '<br/>');

                });
             
            })

        </script>
    </div>
    </form>
</body>
</html>
Code Generate the following output

Get browser details using JQuery

Sunday, September 27, 2015

How to deploy windows phone 8.1 application to device

If you want to run your windows phone 8.1 application to your physical device or you can say phone that you can follow these instruction which is mentioned below:
1. Search windows phone developer registration 8.1 from your window start screen.


windows phone 8.1 registration

2. Register your windows phone now.

windows phone 8.1 registration

3. After successfully registration, set platform of windows phone by build menu in visual studio like:

Configuration manager of build menu
4. Select Platform as "ARM" from Dropdown option.

windows phone device
 5. Now, connect your phone with your computer from USB cable.
6. Run your application.

Friday, September 25, 2015

Bind DataList from database in asp.net c#

Introduction

In this article i will show you how to bind dataList from database table. Also i will give an example of it. In this example i will set the orientation property of items also set columns which is appear on the web page.

The DataList Control

The DataList control is a Data bound control that display 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.
Now , lets take an example.

How to bind DataList Control using the SqlDataSource

Follow some steps for binding Datalist to SqlDataSource . Steps same as Previous post. Basically SqlDataSource is used to connect front-end to  back-end using connection string . Connection string  saved in configuration file.
Now , After establishing connection you have to use property builder through ShowSmart tag.

DataList Property builder
Select Property Builder link , Now after selected a new window will open 


dataList Properties

Run You Application

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
        <asp:DataList ID="DataList1" runat="server" DataKeyField="Id" DataSourceID="SqlDataSource1" Height="285px" RepeatColumns="3" RepeatDirection="Horizontal" Width="134px">
            <ItemTemplate>
                Id:
                <asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id") %>' />
                <br />
                namet:
                <asp:Label ID="nametLabel" runat="server" Text='<%# Eval("namet") %>' />
                <br />
                Income:
                <asp:Label ID="IncomeLabel" runat="server" Text='<%# Eval("Income") %>' />
                <br />
<br />
            </ItemTemplate>
        </asp:DataList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [footerex]"></asp:SqlDataSource>
 
    </div>
    </form>
</body>
</html>

Output
How to use DataList Control in ASP.NET

Thursday, September 24, 2015

Display sum of Columns total in GridView Footer in ASP.Net using C#

Introduction
In this article i will show you how to show total of all rows of GridView column. I will give you an example of this problem.Suppose you have a one numeric type columnn in your data table and you want to add all column values.Also display sum of column in footerRow of the GridView. If we think about algorithm for this type of problem. Algorithm say that first we take a Gridview with Two template  field , One template field have one item template and one footer template such as



  <asp:TemplateField HeaderText ="Name">
                <ItemTemplate >

                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("namet") %>'>

                    </asp:Label>
               


                </ItemTemplate>
                <FooterTemplate >
                    Total:
                 
                </FooterTemplate>
            </asp:TemplateField>

Another template field have same field which is take above such as

<asp:TemplateField HeaderText ="Income">
                <ItemTemplate>
               <asp:Label ID="incomelbl" runat="server" Text='<%# Eval("Income") %>' />

                </ItemTemplate>
                <FooterTemplate >
                   <asp:Label ID="footerlbl" runat="server" Text="" />
                 
                </FooterTemplate>


            </asp:TemplateField>


This whole part cover designing


In codebehind model first we would bind GridView on page Load method. After that handle RowDataBound event . In RowDataBound event  first check Row type is DataRow.

After that find income label in Gridview using findcontrol method.

 if (e.Row.RowType ==DataControlRowType .DataRow)
        {
            var incomsal = e.Row.FindControl("incomelbl") as Label;
            if (incomsal != null)
            {
                total += int.Parse(incomsal.Text);
            }
       
        }

Here Total is a integer variable.
Now Show Total income to footer label then you must find control from the footer row on Page_Load method

  protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page .IsPostBack)
        {
           binddata();
           var footlbl = GridView1.FooterRow.FindControl("footerlbl") as Label;
           if (footlbl != null)
           {
               footlbl.Text  = total.ToString();
           }
        }
   
    }

    After founded , Total value assign to footer label
    Run you program.

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

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:GridView ID="GridView1" runat="server" ShowFooter ="true" AutoGenerateColumns ="false" OnRowDataBound="GridView1_RowDataBound">
        <Columns >

            <asp:TemplateField HeaderText ="Name">
                <ItemTemplate >

                    <asp:Label ID="Label1" runat="server" Text='<%# Eval("namet") %>'>

                    </asp:Label>
               


                </ItemTemplate>
                <FooterTemplate >
                    Total:
                 
                </FooterTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText ="Income">
                <ItemTemplate>
               <asp:Label ID="incomelbl" runat="server" Text='<%# Eval("Income") %>' />

                </ItemTemplate>
                <FooterTemplate >
                   <asp:Label ID="footerlbl" runat="server" Text="" />
                 
                </FooterTemplate>


            </asp:TemplateField>


        </Columns>   



    </asp:GridView>
        <asp:Label ID="result" runat="server" Text=""></asp:Label>
    </div>
    </form>
</body>
</html>

Codebehind
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class additem : System.Web.UI.Page
{
    int total = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page .IsPostBack)
        {
           binddata();
           var footlbl = GridView1.FooterRow.FindControl("footerlbl") as Label;
           if (footlbl != null)
           {
               footlbl.Text  = total.ToString();
           }
        }
     
    }
    public void binddata()
    {
        System.Data.SqlClient.SqlConnection con = new System.Data.SqlClient.SqlConnection();
        con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();
        con.Open();
        System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
        cmd.CommandText = "Select * from [footerex]";
        cmd.Connection = con;
        System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(cmd);
        System.Data.DataSet ds = new System.Data.DataSet();
        da.Fill(ds);
        GridView1.DataSource = ds;
        GridView1.DataBind();
    }

 

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType ==DataControlRowType .DataRow)
        {
            var incomsal = e.Row.FindControl("incomelbl") as Label;
            if (incomsal != null)
            {
                total += int.Parse(incomsal.Text);
            }
         
        }

    }
}

Output
How to display total in GridView Footer in ASP.NET

© Copyright 2013 Computer Programming | All Right Reserved