EDUDOTNET

Monday, December 14, 2015

Pivot table with single column in sql server

- Create Table

CREATE TABLE MyTable
([Id] int)
;

-Insert Data In to Table

INSERT INTO MyTable
([Id])
VALUES
(1),
(2),
(3),
(4),
(5)
;


-Design a query with Pivot 

select *
from
(
  select  CAST(Id AS VARCHAR(15)) +'Col' AS Name , Id AS UserId
  from MyTable
) d
pivot
(
     Min(UserId)
    FOR [Name] IN ([1Col], [2Col],[3Col],[4Col], [5Col])
) piv;


Sunday, August 23, 2015

AWESOME PRIZE - http://forum.edudotnet.com/

http://forum.edudotnet.com/

Thursday, February 26, 2015

ASP.NET 5 Updates and other improvements for Web Developers in Visual Studio 2015 CTP 6

It's time for another Visual Studio 2015 CTP, and with the CTP 6 release in February 2015 you should find a number of improvements that every web developer will enjoy..... more details


Introducing ASP.NET 5

Introducing ASP.NET 5

ASP.NET 5 is an open source web framework for building modern web applications that can be developed and run on Windows, Linux and the Mac. It includes the MVC 6 framework, which now combines the features of MVC and Web API into a single web programming framework.  ASP.NET 5 will also be the basis for SignalR 3 - enabling you to add real time functionality to cloud connected applications. ASP.NET 5 is built on the .NET Core runtime, but it can also be run on the full .NET Framework for maximum compatibility.


Understanding .NET 2015

Tuesday, November 4, 2014

Create Dynamic ASP.NET Server Control Using C# With Theme(Template) Style On Controls

This blog post will provide you how to Add and Create Dynamically ASP.NET Server Controls and place the controls in to an html DIV server Tag. Create your ap.net web application [project] and integrate your required theme(template).
As per your requirement create a web form and design page layout and create a conatainer div with id="myFormContainer" and div as a server control-runat="server", In this div going to add child div, label, textbox, button etc controls dynamically.

Create Dynamic ASP.NET Server Control
All controls list retrieved from "Controls" josn object (List). You can create a json file and Deserialize json object with c# class object, easily create number of controls dynamic with required attributes eg, Id, text etc.. You can also try to controls list retrieved from database table.
Code : Classes, Methods and Events

Step 1: Create basic classes
public class Control
{
public string ID { get; set; }
public string LabelText { get; set; }
}

public class ControlList
{
public List<Control> Controls { get; set; }
}

Step 2: Controls list (Get from json object or database table)
// create the div to add form elements from a controls list
string json = @"{Controls:[{ID:'UserName', LabelText:'User Name'},{ID:'EmailId', LabelText:'Email Address'},{ID:'Password', LabelText:'Password'},{ID:'Phone', LabelText:'Phone Number'}]}";
var controls = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<ControlList>(json);
Step 3: Create Method to bind controls
/// <summary>
/// Create & Add Contols to the container div
/// </summary>
/// <param name="controls"></param>
private void AddControls(ControlList controls)
{
foreach (var control in controls.Controls)
{
//Create Group Container Div
HtmlGenericControl div = new HtmlGenericControl("div");
div.Attributes.Add("class", "form-group");

// create label and add to the div
div.Controls.Add(new Label() { Text = control.LabelText, AssociatedControlID = control.ID, CssClass = "col-md-2 control-label" });

//create the div to add controls eg. textbox, checkbox etc.
HtmlGenericControl divInner = new HtmlGenericControl("div");
divInner.Attributes.Add("class", "col-md-10");

//Create TextBox
divInner.Controls.Add(new TextBox() { ID = control.ID, CssClass = "form-control" });
//Create Validator
divInner.Controls.Add(new RequiredFieldValidator() { ControlToValidate = control.ID, CssClass = "text-danger", ErrorMessage = "The user name field is required." });

div.Controls.Add(divInner);
Container.Controls.Add(div);
}

//create button with event and add to the div
var button = new Button { ID = "btnClick", Text = "Create" };
button.Click += btnClick_OnClick;
Container.Controls.Add(button);
}

Step 4: Call CreateControl() method on OnInit event
/// <summary>
/// Load Controls on OnInit event
/// </summary>
/// <param name="e"></param>
override protected void OnInit(EventArgs e)
{
// create the div to add form elements from a controls list
string json = @"{Controls:[{ID:'UserName', LabelText:'User Name'},{ID:'EmailId', LabelText:'Email Address'},{ID:'Password', LabelText:'Password'},{ID:'Phone', LabelText:'Phone Number'}]}";
var controls = new System.Web.Script.Serialization.JavaScriptSerializer().Deserialize<ControlList>(json);

AddControls(controls); // Method with controls list param
}


HTML Code

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>DEMO - Create Dynamic ASP.NET Server Control</title>
<link href="css/Site.css" rel="stylesheet" />
<link href="css/bootstrap.min.css" rel="stylesheet" />
<link href="css/bootstrap.css" rel="stylesheet" />
</head>
<body>
<div class="container body-content">
<form id="form1" runat="server">
<div>
<h3>DEMO - Create Dynamic ASP.NET Server Control</h3>
<div class="row">
<div class="col-md-8">
<h4><u>User Register</u></h4>
<section id="Form">
<div id="Container" runat="server" class="form-horizontal">
<span class="menu-icon"><i class="fa fa-globe"></i></span>
</div>
</section>
</div>
</div>
</div>
</form>
</div>
</body>

</html>

Thursday, May 8, 2014

Entity Framework 4 - What is the syntax for joining 2 tables then paging them?

Example of joining two tables - Entity Framework

var data = db.Categorie   
   .Join(db.CategoryMap, 
      cat => cat.CategoryId,    
      catmap => catmap.ChildCategoryId, 
      (cat, catmap) => new { Category = cat, CategoryMap = catmap }) 
   .Select(x => x.Category);


 

See more details : http://stackoverflow.com/questions/10222255/entity-framework-4-what-is-the-syntax-for-joining-2-tables-then-paging-them/10222383#10222383