class Program
{
static void Main(string[] args)
{
List<Car> ListOfCar = new List<Car>()
{
new Car {name = "Toyota" , owner = "Alex" , model = 1992},
new Car {name = "Mitsubishi", owner = "Jeff" , model = 2005},
new Car {name = "Land Rover", owner = "Danny", model = 2001},
new Car {name = "BMW" , owner = "Danny", model = 2006},
new Car {name = "Subaru" , owner = "Smith", model = 2003}
};
///BASIC LINQ SINTAX
///
IEnumerable<Car> QueryResult = from car in ListOfCar
select car;
foreach (Car car in QueryResult)
Console.WriteLine(car.name);
///PROJECTION
///based on an existing object type
IEnumerable<CarOwner> QueryResult = from car
in ListOfCar
select new CarOwner { owner_name = car.owner };
foreach (CarOwner owner in QueryResult)
Console.WriteLine(owner.owner_name);
///Projections using Anonymous Types
///type of the variable is unknown until. it�s assigned for the first time.
///
var QueryResult = from car in ListOfCar
select new
{
car_name = car.name,
owner_name = car.owner
};
Console.WriteLine("PROJECTION ANONYMOUS TYPE");
foreach (var entry in QueryResult)
Console.WriteLine(entry.car_name);
///REFINING DATA
///select by conditions
///
IEnumerable<Car> QueryResult = from car in ListOfCar
where car.name == "Subaru"
select car;
foreach (Car car in QueryResult)
Console.WriteLine(car.name);
///ORDER BY
///
IEnumerable<Car> QueryResult = from car in ListOfCar
orderby car.model descending
select car;
foreach (Car car in QueryResult)
Console.WriteLine(car.model + "," + car.name);
///GROUPING
///
var QueryResult = from car in ListOfCar
group car by car.owner into carOnwerGroup
select carOnwerGroup.Key;
///JOINS
///join LINQ
///
List<Car> ListOfCars = new List<Car>()
{
new Car {name = "Mitsubishi", owner = "Jeff" , model = 2005},
new Car {name = "Land Rover", owner = "Danny", model = 2001},
new Car {name = "Subaru" , owner = "Smith", model = 2003},
new Car {name = "Toyota" , owner = "Alex" , model = 1992},
new Car {name = "BMW" , owner = "Danny", model = 2006},
};
List<CarOwner> ListOfCarOwners = new List<CarOwner>()
{
new CarOwner {owner_name = "Danny", age = 22},
new CarOwner {owner_name = "Jeff" , age = 35},
new CarOwner {owner_name = "Smith", age = 19},
new CarOwner {owner_name = "Alex" , age = 40}
};
var QueryResult = from car in ListOfCars
join carowner in ListOfCarOwners on car.name equals carowner.owner_name
select new
{
name = car.name,
owner = car.owner,
owner_age = carowner.age
};
foreach (var entry in QueryResult)
Console.Write(entry.name + "," + entry.owner + "," + entry.owner_age);
Console.Read();
}
}
class Car
{
public string name { get; set; }
public string owner { get; set; }
public int model { get; set; }
}
class CarOwner
{
public string owner_name { get; set; }
public int age { get; set; }
}
full article http://net.tutsplus.com/tutorials/asp-net/net-linq-from-scratch/
Basic and Beginner .NET LINQ
Dynamic File Upload ASP.NET Using JavaScript
JavaScript
var counter = 0;
function AddFileUpload()
{
var div = document.createElement('DIV');
div.innerHTML = '<input id="file' + counter + '" name = "file' + counter + '" type="file" /><input id="Button' + counter + '" type="button" value="Remove" onclick = "RemoveFileUpload(this)" />';
document.getElementById("FileUploadContainer").appendChild(div);
counter++;
}
function RemoveFileUpload(div)
{
document.getElementById("FileUploadContainer").removeChild(div.parentNode);
}
ASPX
<form id="form1" runat="server" enctype="multipart/form-data" method = "post">
<span style ="font-family:Arial">Click to add files</span>
<input id="Button1" type="button" value="add" onclick = "AddFileUpload()" />
<br /><br />
<div id = "FileUploadContainer">
<!--FileUpload Controls will be added here -->
</div>
<br />
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="btnUpload_Click" />
</form>
Code Behind
protected void btnUpload_Click(object sender, EventArgs e)
{
for (int i = 0; i < Request.Files.Count; i++)
{
HttpPostedFile PostedFile = Request.Files[i];
if (PostedFile.ContentLength > 0)
{
string FileName = System.IO.Path.GetFileName(PostedFile.FileName);
PostedFile.SaveAs(Server.MapPath("Files\\") + FileName);
}
}
}
download source code :
source : www.aspsnippets.com
Menambahkan Pane pada ASP.NET Ajax Accordion Melalui CodeBehind
Kita bisa menambahkan pane secara dinamis melalui CodeBehind. berikut adalah kode nya.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="View.aspx.cs" Inherits="AspCs.faq.View" %>
<%@ Register
Assembly="AjaxControlToolkit"
Namespace="AjaxControlToolkit"
TagPrefix="ajax" %>
SelectedIndex="0"
HeaderCssClass="AccordionHeader"
HeaderSelectedCssClass="AccordionHeaderSelected"
ContentCssClass="AccordionContent"
AutoSize="None"
FadeTransitions="true"
TransitionDuration="250"
FramesPerSecond="40"
RequireOpenedPane="true"
SuppressHeaderPostbacks="true">
Get Only Current Page Data From ASP.NET Gridview
private void UpdateAsRead()
{
//get header
foreach (DataControlField col in gvForm.Columns)
{
//Response.Write(col.HeaderText);
}
//get data
foreach (GridViewRow row in gvForm.Rows)
{
int i = 1;
foreach (TableCell cell in row.Cells)
{
//get all rows
if (i == 1)
{
GeneralDao gen = new GeneralDao();
//Response.Write(cell.Text + "
");
string strSQL = @"UPDATE TMIForm SET ldate ='" + gen.GetDateTime() + @"', luserid='" + GetUsername + @"'
WHERE id = '" + cell.Text + @"'";
frmDao.Update(strSQL);
}
i += i;
if (i == 7) { i = 1; }
}
}
}
Disabling the right click on web page
Method 1
In this method we add a javascript method, in this we check if click is right click or left click if it is right click then a message is displayed like "Right click disabled"
document.onmousedown=disableclick;
status="Right Click Disabled";
Function disableclick(e)
{
if(event.button==2)
{
alert(status);
return false;
}
}
But in this solution if you click the right click it displays the message
“Right click disabled”.
If we want to remove the messegebox then this solution do not work.
I am having another simple solution to achieve the same result and also it does not show the messegebox.
Method 2
In this method we set the oncontextmenu="return false" in the body part of the page
so body part will look like
...
So whenever user clicks the right mouse button nothing will happen, no message no context menu.
Sometimes there might be requirement to disable the right click on specific control to achive this we have to follow these steps.
1. remove added code in body (i.e. oncontextmenu=”return false”)
2. Add one table and in its row add the control e.g. datagrid control
3. put the oncontextmenu=”return false” in the
So code will look like this
So by this method context menu on the right click of right mouse click can be disabled.
source: http://www.codeproject.com/Articles/11222/Disabling-the-right-click-on-web-page
Get ListBox Multiple Selected Value
private string GetSelectedCategories()
{
string strItem=string.Empty;
for (int i = 0; i < lbCategories.Items.Count; i++)
{
if (lbCategories.Items[i].Selected)
{
strItem += lbCategories.Items[i].Text;
}
}
return strItem;
}