Thursday, 30 May 2013

How to use RadioButtonList control and do transaction on RadioButtonList using asp.net c# code



How to use RadioButtonList control and do transaction on RadioButtonList using asp.net c# code



Step 1 : First create your website in asp.net and create one .aspx page .

Step2: Open .aspx page and add RadioButtonList control.

<asp:RadioButtonList ID="rbList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="rbList_SelectedIndexChanged"></asp:RadioButtonList>

Step 3 : And add buttons control to do transaction on RadioButtonList.

 <asp:Button ID="BtnAdd" runat="server" OnClick="BtnAdd_Click" Text="Add Item" />
<asp:Button ID="BtnDelete" runat="server" Text="Delete Selcted" OnClick="BtnDelete_Click" />
                      

Step 4 :Add server side code to handle button  event.

 protected void BtnAdd_Click(object sender, EventArgs e)
    {
        ListItem litem = new ListItem();
        itemAdded++;
        litem.Text = "Item" + itemAdded;
        litem.Value = "Item" + itemAdded;
        rbList.Items.Add(litem);
        lblMessage.Text = "Item addedd = " + litem.Value.ToString();
    }

    protected void BtnDelete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < rbList.Items.Count; i++)
        {
            if (rbList.Items[i].Selected == true)
            {
                lblMessage.Text = "Item deleted = " + rbList.Items[i].ToString();
                rbList.Items.RemoveAt(i);              
                break;
            }
        }
    }
    protected void rbList_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblMessage.Text = "Selected value = " + rbList.SelectedValue.ToString();
    }

Step 5 : Just run your page and try to check your code.

//-----------------------  Page Design Code -----------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RadioButtonListContol.aspx.cs" Inherits="RadioButtonListContol" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>

            <table class="auto-style1">
                <tr>
                    <td>
                        <asp:RadioButtonList ID="rbList" runat="server" AutoPostBack="True" OnSelectedIndexChanged="rbList_SelectedIndexChanged"></asp:RadioButtonList>
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>
                        <asp:Button ID="BtnAdd" runat="server" OnClick="BtnAdd_Click" Text="Add Item" />
                        &nbsp;<asp:Button ID="BtnDelete" runat="server" Text="Delete Selcted" OnClick="BtnDelete_Click" />
                        &nbsp;&nbsp;</td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>
                        <asp:Label ID="lblMessage" runat="server"></asp:Label>
                    </td>
                </tr>
            </table>

        </div>
    </form>
</body>
</html>


//-----------------------  Page Server Side Code -----------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class RadioButtonListContol : System.Web.UI.Page
{
    private static int itemAdded = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void BtnAdd_Click(object sender, EventArgs e)
    {
        ListItem litem = new ListItem();
        itemAdded++;
        litem.Text = "Item" + itemAdded;
        litem.Value = "Item" + itemAdded;
        rbList.Items.Add(litem);
        lblMessage.Text = "Item addedd = " + litem.Value.ToString();
    }

    protected void BtnDelete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < rbList.Items.Count; i++)
        {
            if (rbList.Items[i].Selected == true)
            {
                lblMessage.Text = "Item deleted = " + rbList.Items[i].ToString();
                rbList.Items.RemoveAt(i);              
                break;
            }
        }
    }
    protected void rbList_SelectedIndexChanged(object sender, EventArgs e)
    {
        lblMessage.Text = "Selected value = " + rbList.SelectedValue.ToString();
    }
}

How to use CheckBoxList control and do transaction on checkboxlist using asp.net c# code



How to use CheckBoxList control and do transaction on checkboxlist using asp.net c# code


Step 1 : First create your website in asp.net and create one .aspx page .

Step2: Open .aspx page and add checkboxlist control.

<asp:CheckBoxList ID="cbList" runat="server" >
</asp:CheckBoxList>

Step 3 : And add buttons control to do transaction on checkboxlist.

<asp:Button ID="BtnAdd" runat="server" OnClick="BtnAdd_Click" Text="Add Item" />
<asp:Button ID="BtnDelete" runat="server" Text="Delete Selcted" OnClick="BtnDelete_Click" />
<asp:Button ID="BtnSelectAll" runat="server" Text="Select All" OnClick="BtnSelectAll_Click" />
<asp:Button ID="BtnUnSelectAll" runat="server" Text="Un-Select All" OnClick="BtnUnSelectAll_Click" />

Step 4 :Add server side code to handle button  event.

 private static int itemAdded = 0;
 protected void BtnAdd_Click(object sender, EventArgs e)
    {
        ListItem litem = new ListItem();
        itemAdded++;
        litem.Text = "Item" + itemAdded;
        litem.Value = "Item" + itemAdded;
        cbList.Items.Add(litem);
    }

    protected void BtnDelete_Click(object sender, EventArgs e)
    {
        for (int i =0;i< cbList.Items.Count; i++)
        {
            if (cbList.Items[i].Selected == true)
            {
                cbList.Items.RemoveAt(i);
              
            }
        }
    }
    protected void BtnSelectAll_Click(object sender, EventArgs e)
    {
        foreach (ListItem lb in cbList.Items)
        {
            lb.Selected = true;
        }
    }
    protected void BtnUnSelectAll_Click(object sender, EventArgs e)
    {
        foreach (ListItem lb in cbList.Items)
        {
            lb.Selected = false;
        }
    }

Step 5 : Just run your page and try to check your code.

//-----------------------  Page Design Code -----------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUploadControl.aspx.cs" Inherits="FileUploadControl" %>

<!DOCTYPE html>

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CheckBoxListControl.aspx.cs" Inherits="CheckBoxListControl" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .auto-style1 {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
        <div>

            <table class="auto-style1">
                <tr>
                    <td>
                        <asp:CheckBoxList ID="cbList" runat="server">
                        </asp:CheckBoxList>
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>
                        <asp:Button ID="BtnAdd" runat="server" OnClick="BtnAdd_Click" Text="Add Item" />
                        &nbsp;<asp:Button ID="BtnDelete" runat="server" Text="Delete Selcted" OnClick="BtnDelete_Click" />
                        &nbsp;<asp:Button ID="BtnSelectAll" runat="server" Text="Select All" OnClick="BtnSelectAll_Click" />
                        &nbsp;<asp:Button ID="BtnUnSelectAll" runat="server" Text="Un-Select All" OnClick="BtnUnSelectAll_Click" />
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                </tr>
            </table>

        </div>
    </form>
</body>
</html>

//-----------------------  Page Server Side Code -----------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CheckBoxListControl : System.Web.UI.Page
{
    private static int itemAdded = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void BtnAdd_Click(object sender, EventArgs e)
    {
        ListItem litem = new ListItem();
        itemAdded++;
        litem.Text = "Item" + itemAdded;
        litem.Value = "Item" + itemAdded;
        cbList.Items.Add(litem);
    }

    protected void BtnDelete_Click(object sender, EventArgs e)
    {
        for (int i =0;i< cbList.Items.Count; i++)
        {
            if (cbList.Items[i].Selected == true)
            {
                cbList.Items.RemoveAt(i);
               
            }
        }
    }
    protected void BtnSelectAll_Click(object sender, EventArgs e)
    {
        foreach (ListItem lb in cbList.Items)
        {
            lb.Selected = true;
        }
    }
    protected void BtnUnSelectAll_Click(object sender, EventArgs e)
    {
        foreach (ListItem lb in cbList.Items)
        {
            lb.Selected = false;
        }
    }
}

How to use File upload control and show images in Image control



How to use File upload control and show images in Image control


Step 1 : First create your website in asp.net and create one .aspx page .

Step2: Open .aspx page and add Fileupload control .

<asp:FileUpload ID="FileUpload1" runat="server" />

Step 3 : And add button control to upload fileupload images.

<asp:Button ID="BtnSubmit" runat="server" Text="Submit Image" OnClick="BtnSubmit_Click" />

Step 4 :Add image control to show uploaded image on page.

<asp:Image ID="Image1" runat="server"  />

Step 5:  Add Server side code to access image upload transaction.

protected void BtnSubmit_Click(object sender, EventArgs e)
    {
        //check is FileUpload contol selected any item or not
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(Server.MapPath("~/images/" + FileUpload1.FileName));
            Image1.ImageUrl = "~/images/" + FileUpload1.FileName;
        }
    }

Step 6 : Just your page and try to upload files and view uploded image on page.

//-----------------------  Page Design Code -----------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="FileUploadControl.aspx.cs" Inherits="FileUploadControl" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <br />
            <asp:FileUpload ID="FileUpload1" runat="server" />

            <br />
            Select only images
            <br />

            <asp:Button ID="BtnSubmit" runat="server" Text="Submit Image" OnClick="BtnSubmit_Click" />

            <br />

            <br />

            <asp:Image ID="Image1" runat="server"  />
        </div>
    </form>
</body>
</html>

//-----------------------  Page Server Side Code -----------------

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class FileUploadControl : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void BtnSubmit_Click(object sender, EventArgs e)
    {
        //check is FileUpload contol selected any item or not
        if (FileUpload1.HasFile)
        {
            FileUpload1.SaveAs(Server.MapPath("~/images/" + FileUpload1.FileName));
            Image1.ImageUrl = "~/images/" + FileUpload1.FileName;
        }
    }
}

How to use server side Wizard Control using asp.net

How to use server side Wizard Control using asp.net



Step 1 : First create your website in asp.net and create one .aspx page .

Step2: Open .aspx page and add Wizard control.

<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="1" Height="174px" Width="283px">
            <WizardSteps>
                <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1">
                </asp:WizardStep>
                <asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2">
                                   </asp:WizardStep>
            </WizardSteps>
        </asp:Wizard>




Step 3 : Add content to wizard step by adding any control to that block.

<asp:Wizard ID="Wizard1" runat="server" ActiveStepIndex="1" Height="174px" Width="283px">
            <WizardSteps>
                <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1">
                    <asp:Label ID="Label1" runat="server" Text="Wizard Step 1"></asp:Label>
                </asp:WizardStep>
                <asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2">
                    <asp:Label ID="Label2" runat="server" Text="Wizrad Step 2"></asp:Label>
                </asp:WizardStep>
            </WizardSteps>
 </asp:Wizard>
                      



Step 4: Just run your page and try to check your code.

//-----------------------  Page Design Code -----------------

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="WizardControl.aspx.cs" Inherits="WizardControl" %>

<!DOCTYPE html>

<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="1" Height="174px" Width="283px">
            <WizardSteps>
                <asp:WizardStep ID="WizardStep1" runat="server" Title="Step 1">
                    <asp:Label ID="Label1" runat="server" Text="Wizard Step 1"></asp:Label>
                </asp:WizardStep>
                <asp:WizardStep ID="WizardStep2" runat="server" Title="Step 2">
                    <asp:Label ID="Label2" runat="server" Text="Wizrad Step 2"></asp:Label>
                </asp:WizardStep>
            </WizardSteps>
        </asp:Wizard>
    </div>
    </form>
</body>
</html>