-->

Sunday, July 21, 2013

Filter data in datagridview according to combobox in c#

As we have previously studied that datagridview is used for display rows and columns of data in a grid format in windows form. Mostly data are previously defined which are to be shown in datagridview. Sometimes we have to change the data on basis of some conditions.

In previous post we have learnt to bind a datagridview with search option and in else case all the data from database will bind to datagridview in C# language. In this post we will learn to bind datagridview with the selected index changed event of combobox in C#.

The selection changed event of combobox occurs when the value of selected index property changes. We are going to change our data of datagridview according to that changed value.

Let’s create a student class, which will be used to bind our datagridview, having some properties like below:
public class Student
{
public string Name { get; set; }
public int Age { get; set; }
public string Address { get; set; }
public string Branch { get; set; }
}

Create a new list of student that will be the data source of datagridview and insert some records in that list having branch CS or IT as I have inserted in my example using C# language. Set this list as a data source of datagridview.
dataGridView1.DataSource = studentList;

Now when we run this project all the records will be shown in datagridview. We want to change the data of datagridview according to selection changed event. So write the below code in selection changed event of combobox
if (comboBox1.SelectedItem != null)
{
string branch = comboBox1.Text;
var students = studentList.Where(a => a.Branch.Equals(branch));
dataGridView1.DataSource = students.ToList();
}

Run this project now and change the selection value of combobox to CS and we will show the data of datagridview have been changed as following image:

Filter data in datagridview according to combobox in c#

Change the selection value to IT and the data will be changed as following image:


Filter data in datagridview according to combobox in c#
Go for example

How to use TextBox control in ASP.NET

Introduction

The TextBox control is an input control , which allows you to enter text. The TextBox control exists within the System.Web.UI.WebControls namespace.
You can set the style of the TextBox by using the TextMode property . By default , the TextMode property is set to SingleLine to create a single-line HTML . text field but it can also be set to MultiLine for a multiline textbox.
You can convert a mode of TextBox control to a Password control, where the text, which the user types is masked with special symbols such as asterisks (*).
The display width of a textbox is set with its columns property and if it is a multiline textbox , the display height is set with the Rows property.

Public Properties of the TextBox Classes
AutoCompleteType : Obtains or sets a value that indicates the AutoComplete behavior of the TextBox control.
AutoPostBack : Obtains or sets a value that indicates whether an automatic postback to the server occurs when the TextBox control loses focus.
CausesValidation : Obtains or sets a value indicating whether validation is performed when the textbox control is set to validate when a postback occurs.
Columns : Obtains or set the display width of the textbox in characters.
MaxLength : Obtains or sets the maximum number of characters allowed in the textbox.
ReadOnly : Obtains or sets a value indicating whether the contents of the TextBox control can be changed.
Rows : Obtains or sets the number of rows displayed in a multiline textbox.
Text : Obtains or sets the text content of the TextBox control.



TextMode : Obtains or sets the behavior mode (single-line , multiline or password) of the TextBox control.
ValidationGroup : Obtains or sets the group of controls for which the TextBox control causes validation when it postback to the server.
Wrap : Obtains or sets a value indicating whether the text content wraps within a multiline textbox.

Public Event of the TextBox Class
TextChanged : Occurs when the user changes the text of the TextBox.


Example of the TextBox Control

<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox1.Text = " this is the single line textbox";
        TextBox2.Text = " this is the multi-line text box having 10 rows.";
        TextBox4.Text = TextBox3.Text;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
        <asp:Label ID="Label1" runat="server" style="font-weight: 700" Text="Different types of TextBox control"></asp:Label>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click me" />
        <br />
        <br />
        <asp:TextBox ID="TextBox1" runat="server" Height="27px" Width="220px"></asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="TextBox2" runat="server" Rows="10" TextMode="MultiLine"></asp:TextBox>
        <br />
        <br />
        <asp:Label ID="Label2" runat="server" style="font-weight: 700" Text="Enter Password"></asp:Label>
        <br />
        <asp:TextBox ID="TextBox3" runat="server" Height="23px" TextMode="Password" Width="211px"></asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="TextBox4" runat="server" Height="23px" Width="206px"></asp:TextBox>
 
    </div>
    </form>
</body>
</html>

Friday, July 19, 2013

ASP PROGRAM : How to use Wizard Control in ASP.NET

ASP PROGRAM : Introduction
The wizard control provides navigation and a User Interface (UI) to collect related data across multiple steps. It also allows you to implement liner or non-linear navigation through the steps such as skipping unnecessary steps or returning to a previously completed step to change some value. The appearance of the wizard control is fully customized by using templates , skins and style settings; for example , you can use the HeaderTemplate , SideBarTemplate, StartNavigationTemplate , FinishNavigationTemplate , and StepNavigationTemplate properties to customized the interface of the Wizard control.

Public Properties of the Wizard Class
ActiveStep : Obtains the step in the WizardSteps collection , which is currently displayed to the end-user
ActiveStepIndex : Obtains or sets the index value of the current WizardStepBase object.
CancelButtonImageUrl : Obtains or sets the URL of the image displayed for the cancel button.
CancelButtonStyle : Obtains a reference to a collection of style properties that describes the appearance of the cancel button .
CancelButtonText : Obtains or sets the text caption that is displayed for the cancel button.
CancelButtonType : Obtains or sets the type of button that is rendered as the cancel button.
CancelDestinationPageUrl : Obtains or sets the URL that the end user is directed to when they click the cancel button.
CellPadding : Obtains or sets the amount of space between the data of the cell and the cell border.
CellSpacing : Obtains or sets the space between the cells
DisplayCancelButton : Obtains or sets a boolean value showing whether to display a cancel button.
DisplaySideBar : Obtains or sets a Boolean value showing whether to display the sidebar area on the wizard control.

Example of Wizard Control 

When you add a Wizard control on a Web page (Default.aspx), it adds the following code to the source code of the web page
<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0">
            <WizardSteps>
                <asp:WizardStep runat="server" title="Step 1">
                </asp:WizardStep>
                <asp:WizardStep runat="server" title="Step 2">
                </asp:WizardStep>
            </WizardSteps>
        </asp:Wizard>
If you want to add some controls to the Wizard control then you must drop some controls between opening and closing tag of WizardStep

<asp:WizardStep runat="server" title="Step 1">
//Put some controls here
                </asp:WizardStep>
<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void RadioButtonList1_SelectedIndexChanged(object sender, EventArgs e)
    {
     
            result.Text = "your gender are <br/>" + RadioButtonList1.SelectedItem.Text;
   
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
 
        <asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="0">
            <WizardSteps>
                <asp:WizardStep runat="server" title="Step 1">
                    Your Gender are<br />
                    <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="RadioButtonList1_SelectedIndexChanged">
                        <asp:ListItem>Male</asp:ListItem>
                        <asp:ListItem>Female</asp:ListItem>
                    </asp:RadioButtonList>
                    <br />
                    <asp:Label ID="result" runat="server"></asp:Label>
                </asp:WizardStep>
                <asp:WizardStep runat="server" title="Step 2">
                    Welcome
                </asp:WizardStep>
            </WizardSteps>
        </asp:Wizard>
 
    </div>
    </form>
</body>
</html>


Output
ASP PROGRAM : How to use Wizard Control in ASP.NET

ASP PROGRAM : How to use Wizard Control in ASP.NET

Thursday, July 18, 2013

How to Bind Bulleted List using XMLDataSource in ASP.NET


Related Post

<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:BulletedList ID="BulletedList1" runat="server" DataSourceID="XmlDataSource1" DataTextField="Text" DataValueField="url" DisplayMode="HyperLink">
        </asp:BulletedList>
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/database/adver.xml"></asp:XmlDataSource>
   
    </div>
    </form>
</body>
</html>
Output
Bind Bulleted list using xmldata source in asp.net

How to use ImageControl in ASP.NET

Introduction 
The Image control is standard Web Server control, which is used to display an image on a Web page. This control exists within the System.Web.UI.WebControl namespace. You set the Uniform resource Locator (URL) of the image with the ImageUrl property of the Image control. The alignment of the image in relation to other elements on the Web page is specified by setting the ImageAlign property.

Public properties of the image Class
AlternateText : Obtains or sets the alternate text displayed in the image control when the image is not available . Browsers that support the ToolTips featurs display this text as a tooltip.
DescriptionUrl : Obtains or sets the location to a detailed description for the image.
Enabled : Obtains or sets a value indicating whether the control is enabled.
Font : Obtains or sets the font properties for the text associated with the control.
GenerateEmptyAlternateText : Obtains or sets a value indicating whether the control generates an alternate text attribute for an empty string value.
ImageAlign : Obtains or sets the alignment of the image control in relation to other controls on the Web page.

ImageUrl : Obtains or sets the location of an image to where it display in the Image control.

Example of Image control in asp.net

First insert image in any folder or root folder of the website

ImageControl example in asp.net

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

<!DOCTYPE html>

<script runat="server">

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Image ID="Image1" runat="server" ImageUrl ="~/Img/images.jpg" />
    </div>
    </form>
</body>
</html>
Related Post

How to use TextChanged event in ASP.NET

Note : Event occurs only when the AutoPostBack property of the control is set to true.
 Example of TextChanged event of the TextBox when AutoPostBack property is set to true.
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
    protected void TextBox2_TextChanged(object sender, EventArgs e)
    {
        int a = Convert.ToInt32(TextBox1.Text);
        int b = Convert.ToInt32(TextBox2.Text);
        int c = a + b;
        TextBox3.Text = Convert.ToString(c);
      
    }
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
  
        Enter first number:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br />
        Enter Second Number :
        <asp:TextBox ID="TextBox2" runat="server" OnTextChanged="TextBox2_TextChanged" AutoPostBack="True"></asp:TextBox>
        <br />
        Total : <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
  
    </div>
    </form>
</body>
</html>
Output
first enter any number into first Textbox after press TAB key 
and enter second number again press TAB key , Your result will show after pressing tab key.
 
TextChanged Event of the textbox class
 

Wednesday, July 17, 2013

How to use Hyperlink control in ASP.NET

Introduction
The HyperLink control is used to create a link to another Web page that can be a page in your Web application. or anywhere else on the World Wide Web (www) . The HyperLink control exists within the System.Web.UI.WebControls namespace.
You can specify the location of the linked page by specifying its URL on the current page . You can use text as well as an image in the HyperLink control. Text is specified with the Text Property and image is specified by the ImageUrl property . By default , when you click a Hyperlink control , the Hyperlinked content appears in a new browser window. You can set the Target property to the name of a window or frame , as linked in blow

Related Post:

Target property Options of the HyperLink class
_blank : Displays the hyperlinked content in a new window without frames.
_parent : Displays the Hyperlinked content in the immediate frameset parent
_self : Displays the Hyperlinked content in the frame with focus.
_top : Displays the Hyperlinked content in the full window without frames.

Public Properties of the HyperLink Class
ImageUrl : Obtains the path to an image to be displayed for the HyperLink control.
NavigateUrl : Obtains the URL to link to the Web page when the HyperLink control is clicked.
Target : Obtains the target window to display the Web page data when the HyperLink control is clicked.
Text : Obtains the text caption for the HyperLink control 

Example of Hyperlink control in ASP.NET  

<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:HyperLink Target ="_blank" ID="HyperLink1" runat="server" NavigateUrl ="http://dotprogramming.blogspot.com"> Worldbest programming blog on blogspot</asp:HyperLink>
    </div>
    </form>
</body>
</html>
Output 
How to use hyperlink control in asp.net

© Copyright 2013 Computer Programming | All Right Reserved