-->

Saturday, October 26, 2013

How to Get Selected Fields from List Using LINQ: C#

When we bind a list with a control like datagridview, comboBox or listbox, then it will bind all the fields related to list. I have created a list of student with multiple fields i.e. Name, age, city and DOB. Now in this article I will bind only name and age of this list to a Datagridview.

To get selected fields, syntax of LINQ query will be:
var variable = from tempVar in list
select new
{
   tempVar.Field1,
   tempVar.Field2
};

Now in our case of Student class the records should be selected through the following C# line of code:
var selectedFields = from s in stuList
select new
{
s.Name,
s.Age
};
dataGridView1.DataSource = selectedFields.ToList();

In the last line of code, it will bind the list to gridview and show only name and age of the students like in following image:

Get selected fields in LINQ: C# windows forms
If all the LINQ methods are not showing in your program then sure about the namespace in your code file i.e. System. Linq;

See Also: How to Bind DataGridView with DataSet

How to Bind DataGridView to List Of Items: C#

Datagridview is the common control to bind our records in windows forms. I have bound this datagridview to dataset and in this article I will bind a list of student class’s data. I will use the same student class as in my previous post.

Drag-n-Drop a DataGridView on the form and write the following C# line of code in the constructor of the form.
public Form1()
{
InitializeComponent();
dataGridView1.DataSource = stuList;
}

Before running the project, just sure that you have inserted some items in the stuList. To insert some records we can use an in-built Add function of the list. Write the following code to insert records:
stuList.Add(new Student() { Name = "Jacob", Age = 29, City = "London", Dob = new DateTime(1983, 5, 26) });
stuList.Add(new Student() { Name = "Zulia", Age = 31, City = "London", Dob = new DateTime(1981, 5, 26) });
stuList.Add(new Student() { Name = "Brandon", Age = 35, City = "London", Dob = new DateTime(1978, 5, 26) });

The record insertion should be done before the above binding. Run the project and the datagridview will be shown with these three records. The image shown the records in datagridview:

Friday, October 25, 2013

ASP.NET: Programmatically change CheckBoxList Border style

Lets take an simple Example

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        CheckBoxList1.BorderStyle = BorderStyle.Dashed;
     
       
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        CheckBoxList1.BorderStyle = BorderStyle.Dotted;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>CHANGE BORDER STYLE PROGRAMMATICALLY</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:CheckBoxList ID="CheckBoxList1" runat="server" Height="24px" Width="208px">
        <asp:ListItem>ASP.NET CONTROLS</asp:ListItem>
        <asp:ListItem>JAVA CONTROLS</asp:ListItem>
        <asp:ListItem>TURBO CONTROLS</asp:ListItem>
        <asp:ListItem>PYTHON CONTROL</asp:ListItem>
    </asp:CheckBoxList>
    <div>
   
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click"
            Text="DASHED BORDER STYLE" Width="178px" />
   
        <br />
        <br />
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click"
            Text="DOTTED BORDER STYLE" Width="178px" />
   
    </div>
    </form>
</body>

</html>
Output

ASP.NET: Example of Programmatically change CheckBoxList Border color

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void Button1_Click(object sender, EventArgs e)
    {
        CheckBoxList1.BorderColor = System.Drawing.Color.Red;
        CheckBoxList1.BorderStyle = BorderStyle.Dashed;
        CheckBoxList1.BorderWidth = int.Parse("3");
       
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>How to change border color of the CheckBoxList Border color </title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:CheckBoxList ID="CheckBoxList1" runat="server">
            <asp:ListItem>C++ Tutorial</asp:ListItem>
            <asp:ListItem>Java Tutorial</asp:ListItem>
            <asp:ListItem>ASP.NET Tutorial</asp:ListItem>
            <asp:ListItem>Turbo C Tutorial</asp:ListItem>
        </asp:CheckBoxList>
        <br />

        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Change" />
        <br />
        <br />
    </div>
    </form>
</body>

</html>
Output
ASP.NET: Example of Programmatically change CheckBoxList Border color

Difference between ASP.NET and ASP.NET AJAX

ASP.NET

 is a web development model, which is used to deliver interactive, data-driven Web application over the internet. It also consists of a large number of controls, such as a text boxes, button and labels for assembling , configuring, and manipulating code to create hyper Text Markup Language (HTML) pages. You can create ASP.NET application using any CLR compliant language such as Visual basic, C#, Visual c++ and j#. The main features of ASP.NET are as follows.

Better Performance – When you request a Web page for the first time after compiling ASP.NET code, the CLR complies the code and stores the cached copy of the result. Now, for any subsequent calls to the same pag, the cached copy of the result is retrieved instead of going back to the server.

Improved security –ASP.NET has four different methods of authentication:
1. Forms—Allows the ASP.NET application to use its own custom business logic for authentication.
2. Windows—Checks the identity of user against the Windows user accounts that are stored on the web Server. If the credentials of a user match with that of a Windows user account, then the user is authenticated.

Greater Scalability- The session states in ASP.NET are maintained in a separate process on a different machine or database. This enables cross-server sessions to occurs, solving the problem of Web forms when more web servers need to be added as the traffic grows.

Cookie-less Sessions—ASP.NET stores the session state even when the cookies in a Web Browser are disabled. In such a case, the session ID is passed as a part of the Uniform Resource Locator (URL).

Ajax,

 formerly code named as Atlas, is an extension of ASP.NET for developing and implementing AJAX functionality. ASP.NET AJAX Includes both client-side and server-side components that allow the developers to create Web application that are capable to update the data on a website without a complete reload of the page

The following are the advantages of using AJAX:
Asynchronous – Enable asynchronous calls to the web server without making the users wait for the data.

The minimal transfer of the data –Helps in sending only a part of the modified data to the web server minimizing the network traffic and performing the operations quicker. This feature is useful in sites where restricted pipes are allowed for data transfer resulting in improved network performance.

Minimal processing on the web server – Minimizes the processing on the web server as only the necessary data needs to be sent. Now, the server is not required to send a full page back to the server. 

ASP.NET: Programmatically change CheckBoxList Background Color

In previous example we already explain How to use CheckBoxList Control. If you want to change BackGround color on OnIndex change method then use this algorithm.
Step-1 : Add item to the CheckBox List using Show smart tag
Step-2 : Handle SelectedIndexChanged Event
Step-3 : If you want to change  BackGorgound color of the CheckBox List according to CheckBoxList Item then don't use System color enumeration.
Step-4 : Add Style Attribute in every selected item of CheckBoxList.

Complete Code:
<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        foreach (ListItem  item in CheckBoxList1.Items)
        {
            if (item .Selected)
            {
                CheckBoxList1.Attributes.Add("Style", "BackGround-color:" + CheckBoxList1.SelectedItem.Text); 
            }
        }
       
       
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Change CheckBoxList BackGround Color</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True"
            onselectedindexchanged="CheckBoxList1_SelectedIndexChanged">
            <asp:ListItem>Red</asp:ListItem>
            <asp:ListItem>Green</asp:ListItem>
            <asp:ListItem>Yellow</asp:ListItem>
        </asp:CheckBoxList>
   
    </div>
    </form>
</body>

</html>
   Output
ASP.NET: Programmatically change CheckBoxList Background Color

ASP.NET: Programmatically change CheckBoxList Background Color

ASP.NET: Programmatically change CheckBoxList Background Color

Thursday, October 24, 2013

Online Examination Cell project in ASP.NET

Introduction

Examination cell conduct all activity  related to examination cell such as sheet allotment, room allotment ,etc. Directly you can say its a college management ERP software which handle all such types of activities.

This types of project conduct some types of functionality like:


  • Administrator has a privilege to create, modify and delete the test papers and its particular questions.
  • User can register, login and give the test with his specific id, and can see the results as well
  • Technical college software’s examination module is mainly concerned upon
  • In-college examination including sessionals and practical
  • External exams management
  • Admit card managing
  • External exams managing of colleges centered in the college
  • Schedule management
  • This module will look upon all basic as well as advanced needs of an examination cell.

Module of the project

This Project is dividing into the three Types of user

  1. Super user.
  2. Administrator.
  3. Faculty member
  4. Student

Super user
Super user is the top level faculty of organization. Handle many modules by the super user. Like
  • Create user.
  • Allotted Course To The Faculty.
  • Send Message To The Faculty.
Administrator
An administrator is the Exam –cell in charges of organization also handle many modules by the Administrator Like
  •  Sheet allotment.
  •  Duty chart.
  •  Paper Collection.
  •  Report generation.
  •  Notice generation.
  • University result
  •  Model exam question papers
  • Unit/sessional test time table
  •  Current News
  •  Course allotment
  •  Paper Collection
If you want to purchase this please contact me on :  narenkumar851@gmail.com
© Copyright 2013 Computer Programming | All Right Reserved