Wednesday, 1 October 2014

How to find dictionary duplicate values in C#

For Reference:

//initialize a dictionary with keys and values.    
Dictionary<int, string> plants = new Dictionary<int, string>() {    
    {1,"Speckled Alder"},    
    {2,"Apple of Sodom"},    
    {3,"Hairy Bittercress"},    
    {4,"Pennsylvania Blackberry"},    
    {5,"Apple of Sodom"},    
    {6,"Water Birch"},    
    {7,"Meadow Cabbage"},    
    {8,"Water Birch"}    
};  
  
Response.Write("<b>dictionary elements........</b><br />");
        
//loop dictionary all elements   
foreach (KeyValuePair<int, string> pair in plants)  
{
    Response.Write(pair.Key + "....."+ pair.Value+"<br />");
}  
  
//find dictionary duplicate values.  
var duplicateValues = plants.GroupBy(x => x.Value).Where(x => x.Count() > 1);

Response.Write("<br /><b>dictionary duplicate values..........</b><br />");

//loop dictionary duplicate values only            
foreach(var item in duplicateValues)  
{
    Response.Write(item.Key+"<br />");
}   


1.
counties = XDocument.Load(HttpContext.Current.Server.MapPath("/data/counties.xml"))
.Descendants("Row")
.GroupBy(i => i.Attribute("Code").Value)
.Where(g => g.Count() == 1)
.Select(g => new { Code = g.Key, Desc = g.First().Attribute("Descrip").Value })
.ToDictionary(x => x.Code, x => x.Desc);
2. 

How to Remove Duplicates and Get Distinct records from List using LINQ?

using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
namespace AbundantCode
{
internal class Program
{
//How to Remove Duplicates and Get Distinct records from List using LINQ ?
private static void Main(string[] args)
{
List<Employee> employees = new List<Employee>()
{
new Employee { EmpID = 1 , Name ="AC"},
new Employee { EmpID = 2 , Name ="Peter"},
new Employee { EmpID = 3 , Name ="Michael"},
new Employee { EmpID = 3 , Name ="Michael"}
};
//Gets the Distinct List
var DistinctItems = employees.GroupBy(x => x.EmpID).Select(y => y.First());
foreach(var item in DistinctItems)
Console.WriteLine(item.Name);
Console.ReadLine();
}
}
public class Employee
{
public string Name { get; set; }
public int EmpID { get; set; }
}
}
3. 

How to find the duplicate items in a list?

string[] ss ={ "1","1","1"};
            List<string> myList = new List<string>();
 
 
            foreach (String s in&nbsp;ss)
            {
                if (!myList.Contains(s))
                {
                 myList.Add(s);
                }
            }
 
            foreach (String s in&nbsp;myList)
            {
                Console.WriteLine(s);
            }

Sunday, 28 September 2014

Nested ListView


Output

----------------------------------
<style type="text/css">
        .collapse
        {
            background-position: left -172px;
            height: 14px;
            width: 13px;
            background-repeat: no-repeat;
            background-image: url('DXR1.png');
            cursor: pointer;
        }
        .expand
        {
            background-position: -14px -187px;
            height: 14px;
            width: 13px;
            background-repeat: no-repeat;
            background-image: url('DXR.png');
            cursor: pointer;
        }
        table
        {
            border: solid 0px black;
        }
        table td
        {
            border-right: solid 0px black;
            border-bottom: solid 0px black;
        }
        table th
        {
            border-bottom: solid opx black;
        }
        .SUBDIV table
        {
            border: 0px;
            border-left: 0px solid black;
        }
    </style>
    <script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script>
    <script language="javascript" type="text/javascript">
        $(document).ready(function () {
            // THIS IS FOR HIDE ALL DETAILS ROW
            $(".SUBDIV table tr:not(:first-child)").not("tr tr").hide();
            $(".SUBDIV .btncolexp").click(function () {
                $(this).closest('tr').next('tr').toggle();
                //this is for change img of btncolexp button
                if ($(this).attr('class').toString() == "btncolexp collapse") {
                    $(this).addClass('expand');
                    $(this).removeClass('collapse');
                }
                else {
                    $(this).removeClass('expand');
                    $(this).addClass('collapse');
                }
            });
        });
    </script>
    <div>
        <asp:ListView ID="ListView1" runat="server" OnItemDataBound="ListView1_ItemDataBound">
            <LayoutTemplate>
                <table width="100%" border="1" cellpadding="0" cellspacing="0">
                   <tr id="Tr2" style="background-color: #DCDCDC; color: #000000;">
                        <th style="width: 2%">
                            &nbsp;
                        </th>
                        <th id="Th2" style="width: 20%">
                            Manager Name
                        </th>
                        <th id="Th3" style="width: 20%">
                            A
                        </th>
                        <th id="Th4" style="width: 20%">
                            B
                        </th>
                        <th id="Th5" style="width: 20%">
                            C
                        </th>
                        <th id="Th6" style="width: 20%">
                            D
                        </th>
                    </tr>
                </table>
                <div runat="server" id="itemPlaceHolder">
                </div>
            </LayoutTemplate>
            <ItemTemplate>
                <div id="Div1" class="SUBDIV" runat="server">
                    <table width="100%" border="0" cellpadding="0" cellspacing="0">
                        <tr style="background-color: #F3FCEC; color: #000000;">
                            <td style="width: 2%">
                                <div class="btncolexp collapse">
                                    &nbsp;
                                </div>
                            </td>
                            <td style="width: 20%">
                                <asp:HiddenField ID="HdnManagerId" runat="server" Value='<%#Eval("MID") %>' />
                                <asp:Label ID="PriceDescLabel" runat="server" Text='<%# Eval("ManagerName") %>' />
                            </td>
                            <td style="width: 20%">
                                <asp:Label ID="ALabel" runat="server" Text='<%# Eval("A") %>' />
                            </td>
                            <td style="width: 20%">
                                <asp:Label ID="BLabel" runat="server" Text='<%# Eval("B") %>' />
                            </td>
                            <td style="width: 20%">
                                <asp:Label ID="CLabel" runat="server" Text='<%# Eval("C") %>' />
                            </td>
                            <td style="width: 20%">
                                <asp:Label ID="DLabel" runat="server" Text='<%# Eval("D") %>' />
                            </td>
                        </tr>
                        <tr>
                            <td colspan="6" style="width:100%;">
                                    <asp:ListView ID="ListView2" runat="server">                                        
                                        <LayoutTemplate>
                                            <table id="Table1" runat="server" style="width:100.7%; margin: -3px -3px -3px -3px;">
                                                <tr id="Tr1" runat="server">
                                                    <td id="Td1" runat="server">
                                                        <table id="itemPlaceholderContainer" runat="server" style="width: 100%;
                                                            background-color: #A3F5F3; border-collapse: collapse; border-color: #999999;
                                                            border-style: none; border-width: 1px; font-family: Verdana, Arial, Helvetica, sans-serif;">
                                                            <tr id="itemPlaceholder" runat="server">
                                                            </tr>
                                                        </table>
                                                    </td>
                                                </tr>
                                            </table>
                                        </LayoutTemplate>
                                        <ItemTemplate>
                                            <tr style="background-color: #A3F5F3; color: #000000;">
                                                <td style="width: 2%">
                                                    &nbsp;
                                                </td>
                                                <td style="width: 20%">
                                                    <asp:Label ID="PriceDescLabel" runat="server" Text='<%# Eval("PriceDesc") %>' />
                                                </td>
                                                <td style="width: 20%">
                                                    <asp:Label ID="ALabel" runat="server" Text='<%# Eval("A") %>' />
                                                </td>
                                                <td style="width: 20%">
                                                    <asp:Label ID="BLabel" runat="server" Text='<%# Eval("B") %>' />
                                                </td>
                                                <td style="width: 20%">
                                                    <asp:Label ID="CLabel" runat="server" Text='<%# Eval("C") %>' />
                                                </td>
                                                <td style="width: 20%">
                                                    <asp:Label ID="DLabel" runat="server" Text='<%# Eval("D") %>' />
                                                </td>
                                            </tr>
                                        </ItemTemplate>
                                    </asp:ListView>
                            </td>
                        </tr>
                    </table>
                </div>
            </ItemTemplate>
        </asp:ListView>
    </div>
---------------------------------------------------------------------
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;

namespace HierachicalListViewDemo
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        string connection = ConfigurationManager.ConnectionStrings["TestConnectionString"].ConnectionString;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                PopulateFirstListData();
            }
        }
        private void PopulateFirstListData()
        {
            SqlConnection con = new SqlConnection(connection);
            SqlDataAdapter da = new SqlDataAdapter("SELECT MAX(ManagerName) as ManagerName, MAX(PriceDesc) as PriceDesc, Sum(A) as A, SUM(B) as B,SUM(C) as C,SUM(D) as D, MID FROM dbo.ExceptionList excp left join dbo.Manager Mgr on excp.ManagerId = Mgr.MID Group by MID", con);
            DataSet ds = new DataSet();
            da.Fill(ds);

            ListView1.DataSource = ds;
            ListView1.DataBind();
        }
        private DataSet PopulateSecondListData(int ManagerId)
        {
            SqlConnection con = new SqlConnection(connection);
            SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM dbo.ExceptionList where ManagerId=" + ManagerId, con);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds;
        }

        protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                HiddenField hdnManagerId = (HiddenField)e.Item.FindControl("HdnManagerId");
                ListView listview2 = (ListView)e.Item.FindControl("ListView2");
                DataSet list2ds = PopulateSecondListData(Convert.ToInt32(hdnManagerId.Value));

                listview2.DataSource = list2ds;
                listview2.DataBind();
            }
        }
    }
}
--------------------------------------------------------
<add name="TestConnectionString" connectionString="Data Source=.;Initial Catalog=test;Integrated Security=True" providerName="System.Data.SqlClient" />
--------------------------------------------------------
Tables
-------------------------------
CREATE TABLE [dbo].[Region](
[RID] [int] IDENTITY(1,1) NOT NULL,
[RegionName] [varchar](50) NOT NULL,
 CONSTRAINT [PK_Region] PRIMARY KEY CLUSTERED 
(
[RID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[Region] ON
INSERT [dbo].[Region] ([RID], [RegionName]) VALUES (1, N'North')
INSERT [dbo].[Region] ([RID], [RegionName]) VALUES (2, N'South')
INSERT [dbo].[Region] ([RID], [RegionName]) VALUES (3, N'East')
INSERT [dbo].[Region] ([RID], [RegionName]) VALUES (4, N'West')
SET IDENTITY_INSERT [dbo].[Region] OFF
/****** Object:  Table [dbo].[Manager]    Script Date: 09/28/2014 23:58:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Manager](
[MID] [int] IDENTITY(1,1) NOT NULL,
[ManagerName] [varchar](50) NOT NULL,
[RegionId] [int] NOT NULL,
 CONSTRAINT [PK_Manager] PRIMARY KEY CLUSTERED 
(
[MID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[Manager] ON
INSERT [dbo].[Manager] ([MID], [ManagerName], [RegionId]) VALUES (1, N'Raju', 1)
INSERT [dbo].[Manager] ([MID], [ManagerName], [RegionId]) VALUES (2, N'Raja', 2)
INSERT [dbo].[Manager] ([MID], [ManagerName], [RegionId]) VALUES (3, N'Sai', 3)
INSERT [dbo].[Manager] ([MID], [ManagerName], [RegionId]) VALUES (4, N'Pravin', 4)
INSERT [dbo].[Manager] ([MID], [ManagerName], [RegionId]) VALUES (5, N'Mahesh', 1)
INSERT [dbo].[Manager] ([MID], [ManagerName], [RegionId]) VALUES (6, N'Lakshmi', 2)
INSERT [dbo].[Manager] ([MID], [ManagerName], [RegionId]) VALUES (7, N'Gandharv', 3)
INSERT [dbo].[Manager] ([MID], [ManagerName], [RegionId]) VALUES (8, N'Avinash', 4)
INSERT [dbo].[Manager] ([MID], [ManagerName], [RegionId]) VALUES (9, N'Govind', 1)
INSERT [dbo].[Manager] ([MID], [ManagerName], [RegionId]) VALUES (10, N'Harish', 2)
SET IDENTITY_INSERT [dbo].[Manager] OFF
/****** Object:  Table [dbo].[ExceptionList]    Script Date: 09/28/2014 23:58:23 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[ExceptionList](
[PriceId] [int] IDENTITY(1,1) NOT NULL,
[PriceDesc] [varchar](500) NOT NULL,
[A] [int] NULL,
[B] [int] NULL,
[C] [int] NULL,
[D] [int] NULL,
[RegionId] [int] NOT NULL,
[ManagerId] [int] NOT NULL,
 CONSTRAINT [PK_ExceptionList] PRIMARY KEY CLUSTERED 
(
[PriceId] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
SET IDENTITY_INSERT [dbo].[ExceptionList] ON
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (1, N'Testing_1', 6, 8, 5, NULL, 1, 1)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (2, N'Testing_2', 7, NULL, 8, NULL, 2, 2)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (3, N'Testing_3', NULL, NULL, 7, 8, 3, 3)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (4, N'Testing_4', NULL, 7, 7, NULL, 4, 4)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (5, N'Testing_5', 7, 7, 7, NULL, 1, 5)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (6, N'Testing_6', NULL, 7, NULL, 4, 2, 6)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (7, N'Testing_7', 8, NULL, 7, NULL, 3, 7)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (8, N'Testing_8', NULL, 7, NULL, 2, 4, 8)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (9, N'Testing_9', 9, NULL, 7, NULL, 1, 9)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (10, N'Testing_10', NULL, NULL, NULL, 3, 2, 10)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (11, N'Testing_11', NULL, NULL, 7, NULL, 3, 1)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (12, N'Testing_12', 12, 7, NULL, 3, 4, 2)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (13, N'Testing_13', NULL, NULL, NULL, NULL, 3, 3)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (14, N'Testing_14', 22, 7, 7, 6, 2, 4)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (15, N'Testing_15', 6, 8, 5, NULL, 1, 1)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (16, N'Testing_16', 7, NULL, 8, NULL, 2, 2)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (17, N'Testing_32', NULL, NULL, 7, 8, 3, 3)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (18, N'Testing_41', NULL, 7, 7, NULL, 4, 4)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (19, N'Testing_51', 7, 7, 7, NULL, 1, 5)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (20, N'Testing_61', NULL, 7, NULL, 4, 2, 6)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (21, N'Testing_71', 8, NULL, 7, NULL, 3, 7)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (22, N'Testing_81', NULL, 7, NULL, 2, 4, 8)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (23, N'Testing_91', 9, NULL, 7, NULL, 1, 9)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (24, N'Testing_101', NULL, NULL, NULL, 3, 2, 10)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (25, N'Testing_111', NULL, NULL, 7, NULL, 3, 1)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (26, N'Testing_121', 12, 7, NULL, 3, 4, 2)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (27, N'Testing_131', NULL, NULL, NULL, NULL, 3, 3)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (28, N'Testing_141', 22, 7, 7, 6, 2, 4)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (29, N'Testing_12', 6, 8, 5, NULL, 1, 1)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (30, N'Testing_22', 7, NULL, 8, NULL, 2, 2)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (31, N'Testing_32', NULL, NULL, 7, 8, 3, 3)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (32, N'Testing_42', NULL, 7, 7, NULL, 4, 4)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (33, N'Testing_52', 7, 7, 7, NULL, 1, 5)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (34, N'Testing_62', NULL, 7, NULL, 4, 2, 6)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (35, N'Testing_72', 8, NULL, 7, NULL, 3, 7)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (36, N'Testing_82', NULL, 7, NULL, 2, 4, 8)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (37, N'Testing_92', 9, NULL, 7, NULL, 1, 9)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (38, N'Testing_102', NULL, NULL, NULL, 3, 2, 10)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (39, N'Testing_112', NULL, NULL, 7, NULL, 3, 1)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (40, N'Testing_122', 12, 7, NULL, 3, 4, 2)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (41, N'Testing_132', NULL, NULL, NULL, NULL, 3, 3)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (42, N'Testing_142', 22, 7, 7, 6, 2, 4)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (43, N'Testing_152', 6, 8, 5, NULL, 1, 1)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (44, N'Testing_162', 7, NULL, 8, NULL, 2, 2)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (45, N'Testing_322', NULL, NULL, 7, 8, 3, 3)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (46, N'Testing_412', NULL, 7, 7, NULL, 4, 4)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (47, N'Testing_512', 7, 7, 7, NULL, 1, 5)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (48, N'Testing_612', NULL, 7, NULL, 4, 2, 6)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (49, N'Testing_712', 8, NULL, 7, NULL, 3, 7)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (50, N'Testing_812', NULL, 7, NULL, 2, 4, 8)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (51, N'Testing_912', 9, NULL, 7, NULL, 1, 9)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (52, N'Testing_1012', NULL, NULL, NULL, 3, 2, 10)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (53, N'Testing_1112', NULL, NULL, 7, NULL, 3, 1)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (54, N'Testing_1212', 12, 7, NULL, 3, 4, 2)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (55, N'Testing_1312', NULL, NULL, NULL, NULL, 3, 3)
INSERT [dbo].[ExceptionList] ([PriceId], [PriceDesc], [A], [B], [C], [D], [RegionId], [ManagerId]) VALUES (56, N'Testing_142', 22, 7, 7, 6, 2, 4)
SET IDENTITY_INSERT [dbo].[ExceptionList] OFF
/****** Object:  ForeignKey [FK_ExceptionList_Manager]    Script Date: 09/28/2014 23:58:23 ******/
ALTER TABLE [dbo].[ExceptionList]  WITH CHECK ADD  CONSTRAINT [FK_ExceptionList_Manager] FOREIGN KEY([ManagerId])
REFERENCES [dbo].[Manager] ([MID])
GO
ALTER TABLE [dbo].[ExceptionList] CHECK CONSTRAINT [FK_ExceptionList_Manager]
GO
/****** Object:  ForeignKey [FK_ExceptionList_Region]    Script Date: 09/28/2014 23:58:23 ******/
ALTER TABLE [dbo].[ExceptionList]  WITH CHECK ADD  CONSTRAINT [FK_ExceptionList_Region] FOREIGN KEY([RegionId])
REFERENCES [dbo].[Region] ([RID])
GO
ALTER TABLE [dbo].[ExceptionList] CHECK CONSTRAINT [FK_ExceptionList_Region]
GO
/****** Object:  ForeignKey [FK_Manager_Region]    Script Date: 09/28/2014 23:58:23 ******/
ALTER TABLE [dbo].[Manager]  WITH CHECK ADD  CONSTRAINT [FK_Manager_Region] FOREIGN KEY([RegionId])
REFERENCES [dbo].[Region] ([RID])
GO
ALTER TABLE [dbo].[Manager] CHECK CONSTRAINT [FK_Manager_Region]
GO

Thursday, 25 September 2014

ListView Operations in Asp.Net

List View Links

http://www.nullskull.com/q/10111285/hyperlink-in-a-listview.aspx

Hyperlink in ListView


<asp:HyperLink runat="server" id="LoggedUserGroupList" Text="<%# DataBinder.Eval(Container.DataItem, "col1") %>"
        NavigateUrl='<%#"groupDisplay.aspx?groupName=" & DataBinder.Eval(Container.DataItem, "col2")%>'>
 </asp:HyperLink>

 where,
col1 = text that would appear
col2 = column in the datasource that would give the group name. OR

           
Hi,
                I've done something similar like this (note all the quotes and apostrophes):
          <asp:HyperLink ID="lnkView" runat="server" Text="View"
          NavigateUrl='<%#"~/Users/Transactions.aspx?account=" + Eval("AccountID")%>' />
 
 
List View using Templates
CRUD OPERATION USING LIST VIEW
Edit,Update,Delete and Insert in List View Control 

Various Data Bound Controls Used in ASP.Net

 

New trends in ASP.NET data binding: the ListView control

How to Use ASP.NET 3.5 ListView & DataPager


Friday, 19 September 2014

Shortcut keys used in Visual Studio


Ctrl+M+O => Collapsing all functions

Ctrl+L       => Expanding all functions

prop+Tab Press  => Write whole property

foreach /if/ While/ do-while + Tab Press    => Write all if statement

F5           =>   Start your project in debug mode
Ctrl + Spacebar  => Intelligence 
Ctrl+ F5  => Starts the project without debugging
Ctrl+Shift+U  => Converts the currently selected text to upper case



Wednesday, 27 August 2014

Difference Between char, varchar & nvarchar DataType


Char DataType

Char datatype which is used to store fixed length of characters. Suppose if we declared char(50) it will allocates memory for 50 characters. Once we declare char(50) and insert only 10 characters of word then only 10 characters of memory will be used and other 40 characters of memory will be wasted.

varchar DataType

Varchar means variable characters and it is used to store non-unicode characters. It will allocate the memory based on number characters inserted. Suppose if we declared varchar(50) it will allocates memory of 0 characters at the time of declaration. Once we declare varchar(50) and insert only 10 characters of word it will allocate memory for only 10 characters.

nvarchar DataType

nvarchar datatype same as varchar datatype but only difference nvarchar is used to store Unicode characters and it allows you to store multiple languages in database. nvarchar datatype will take twice as much space to store extended set of characters as required by other languages.

Thursday, 21 August 2014

Microsoft Visual Studio 2012 Ultimate Product Keys

Here are some product keys:

YKCW6-BPFPF-BT8C9-7DCTH-QXGWC
RBCXF-CVBGR-382MK-DFHJ4-C69G8
YQ7PR-QTHDM-HCBCV-9GKGG-TB2TM

Download Microsoft Visual Studio 2012 Ultimate:
ISO Image (1,5 GB)
Web Installer

Leave a comment if it's working for you.
If not, I'll post new ones.

Monday, 11 August 2014

Encrypt and Decrypt QueryString Parameter Values in ASP.Net Using C#

 

QueryString encrypt from a GridView HyperLink?

 Step-1

<asp:TemplateField HeaderText="View">
      <ItemTemplate>
           <asp:HyperLink id="hlLinkView" Text="View" runat="server"/>
      </ItemTemplate>
</asp:TemplateField>

 Step-2

In RowDataBound Event of GridView

if (e.Row.RowType == DataControlRowType.DataRow)
{
   Label lblPoNoEncrypt = ((Label) e.Row.FindControl("lblPoNo"));
((HyperLink)e.Row.FindControl("hlLinkView")).NavigateUrl = "abc.aspx?Parameter=" + Encrypt(lblAbcEncrypt.Text);

}

Step-3

Add this function


public string Encrypt(string clearText)
        {
            string EncryptionKey = "MAKV2SPBNI99212";
            byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
            using (Aes encryptor = Aes.Create())
            {
                Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
                encryptor.Key = pdb.GetBytes(32);
                encryptor.IV = pdb.GetBytes(16);
                using (MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(clearBytes, 0, clearBytes.Length);
                        cs.Close();
                    }
                    clearText = Convert.ToBase64String(ms.ToArray());
                }
            }
            return clearText;
        }


Step-4:-

At decryption side add this code:

 

private string Decrypt(string cipherText)
        {
            string EncryptionKey = "MAKV2SPBNI99212";
            cipherText = cipherText.Replace(" ", "+");
            byte[] cipherBytes = Convert.FromBase64String(cipherText);
            using (Aes encryptor = Aes.Create())
            {
                Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
                encryptor.Key = pdb.GetBytes(32);
                encryptor.IV = pdb.GetBytes(16);
                using (MemoryStream ms = new MemoryStream())
                {
                    using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
                    {
                        cs.Write(cipherBytes, 0, cipherBytes.Length);
                        cs.Close();
                    }
                    cipherText = Encoding.Unicode.GetString(ms.ToArray());
                }
            }
            return cipherText;
        }


Step-5:

if (Request.QueryString["Parameter"] != "")
 {
    txt_No.Text = Decrypt(HttpUtility.UrlDecode(Request.QueryString["PoNo"].ToString()));

}

 

Reference: -

Encrypt and Decrypt QueryString Parameter Values in ASP.Net

using C# and VB.Net