Skip to main content

Posts

How to add a static item to a databound dropdownlist

In this post i will show how to add static item to dropdownlist like a dropdown that displays one static item such as "select" while the rest of the items are data bound, then check out the code below: 

Set the AppendDataBoundItems property of the dropdownlist to True, and add in the static list item. Your dropdown will look something like this:

 <asp:DropDownList ID="ddlCountry" runat="server" AppendDataBoundItems="true">             <asp:ListItem Text="Select" Value="-1"></asp:ListItem>         </asp:DropDownList>
check out the complete code

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="ser…

How to use anonymous and Lambda expression in .net

In this post I will discuss how to use anonymous and lambda expression in .net. Imagine we have a simple example in c# that simply add two numbers.
using System; using System.Collections.Generic; using System.Linq; using System.Text; class Program {     publicdelegateint Fn(int a, int b);     staticvoid Main(string[] args)     {         Fn add = new Fn(Add);         Console.WriteLine(add(1, 2));     }     publicstaticint Add(int a, int b)     {         return (a + b);     } }
Let’s refactor the delegate instance version of the code to use an anonymous method. What is anonymous method? Anonymous methods are a new language feature in C# 2.0. Anonymous methods allow us to define a code block where a delegate object is acceptable. Let’s convert the above code using anonymous code. Remove the following method from the delegate instance version
publicstaticint Add(int a, int b)         {             return (a + b);         }
And replace following code with
Fn add = new Fn(Add); With this on…

3 Tier Architecture in ASP.NET

In this post i will show how to create 3 -tier architecture in asp.net.Before going to technical details,I will describe some details about what is 3 tier architecture and what are the main components of 3 tier architecture.

The three-tier architecture was comes into existence to improve management of code and contents and to improve the performance of the web based applications.There are mainly three layers in three-tier architecture. These are define as follows…




1.  UI(InsertCustomer.aspx): First layer Presentation contains mainly the interface code, and this is shown to user. This code could contain any technology that can be used on the client side like HTML, JavaScript or VBScript etc.

2. Business Logic(CustomerBL.cs) : Second layer is Business Logic which contains all the code of the server-side .This layer have code to interact with database database and to query, manipulate, pass data to user interface and handle any input from the UI as well.

3. DataAccess Layer(CustomerDAL.c…

CASE Statement Equivalent in LINQ

In this post i will show you how how to generate "Case statement" from linq.Let's say that you want to select rows from [Order Details] table in Northwind database something like this:  If the product UnitPrice is >10 then you want to display it as "High"If the product UnitPrice is <5 then you want to display it as "Low" otherwise "Average"
Our query should include the switch case  clause. Something like this:

SELECT
(
CASE
WHEN UnitPrice >10 THEN 'High'
WHEN UnitPrice <5 THEN 'Low'
ELSE 'Average'
END ) AS ProductPrice
FROM [Order Details]



using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; namespace Linq_Tips { class Program { staticvoid Main(string[] args) { NorthwindDataContext dc = new NorthwindDataContext(); var query = from o in dc.Order_Details select new …

Linq and Sql "where in" Operator

In this post i will  show you how to generate "where in " clause in Linq to Sql. Imagine that we want to select rows from Products table in Northwind database where ProductId matches 3,4, 10. Our query should include the Where IN clause. Something like this:

SELECT *FROM Products WHERE ProductID in (3,4,10)

using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Reflection; namespace Linq_Tips { class Program { staticvoid Main(string[] args) { //Create a list List<int> list = new List<int>(); //Add items in list list.AddRange(newint[] {3, 4, 10 }); NorthwindDataContext dc = new NorthwindDataContext(); //Query database var query = from product in dc.Products where list.Contains(product.ProductID) select product; Console.WriteLine(query); …

How to use Jquery fullcalender in asp.net

This snippet will show how how to use Jquery fullcalender in asp.net Open Microsoft Visual Studio .NET. In Visual C# .NET, create a new website  named Fullcalender.Add  following code to Default.aspx page.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FullCalender.aspx.cs" Inherits="FullCalender" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><headrunat="server"><title></title><scriptsrc="Scripts/jquery-1.4.1.js"type="text/javascript"></script>     <script src="Scripts/fullcalendar.js" type="text/javascript"></script>     <script src="Scripts/gcal.js" type="text/javascript"></script>     <link href="Styles/fullcalendar.css" rel="styleshe…