Sponsored Ad

Monday, May 3, 2010

How to Get Selected Values of CheckBoxList in C#

 

This sample code will help you to find the CheckBoxList selected values. This code loop through all the checkbox values using foreach and assign comma separated selected values in to label.

 

How to Get Selected Values of CheckBoxList in C#

 

 

Source 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 btnGetSelected_Click(object sender, EventArgs e)
    {
        lblSelected.Text = "Your selected check box values are: <br>";
        foreach (ListItem lst in chkList.Items)
        {
            if (lst.Selected == true)
            {
                lblSelected.Text += lst.Text + ", ";
            }
        }
    }
</script>

<html>
<head>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:CheckBoxList ID="chkList" runat="server">
                <asp:ListItem>IndiHub.com</asp:ListItem>
                <asp:ListItem>BharatClick.com</asp:ListItem>
                <asp:ListItem>SharePointBank.com</asp:ListItem>
                <asp:ListItem>SoftwareTestingNet.com</asp:ListItem>
            </asp:CheckBoxList>
            <br />
            <asp:Button ID="btnGetSelected" runat="server" Text="Get Selected Values" OnClick="btnGetSelected_Click" />
            <br />
            <asp:Label ID="lblSelected" runat="server" Text=""></asp:Label>
        </div>
    </form>
</body>
</html>

How to Find Checkbox Status in C#

 

This sample code will help you to find checkbox status on check change.

 

How to Find Checkbox Status in C#

 

How to Find Checkbox Status in C#

 

Source 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 chkTest_CheckedChanged(object sender, EventArgs e)
    {
        if (chkTest.Checked)
        {
            Response.Write("you have checked the checkbox");
        }
        else
        {
            Response.Write("you have unchecked the checkbox");
        }
    }
</script>

<html>
<head>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:CheckBox ID="chkTest" runat="server" AutoPostBack="true" OnCheckedChanged="chkTest_CheckedChanged"    />
        </div>
    </form>
</body>
</html>

Saturday, May 1, 2010

How to Create First Windows Application and Run in VS 2005 – C#

 

Creating a first project is always a tough talk. Let me demonstrate you to create a windows application in VS 2005 using C#.

 

Step 1: Open VS 2005 (IDE)

VS 2005

 

Step 2: Select Visual C# and windows application and give project name .

Select Visual C# and Windows Application and Given name to project

Step 3: form.cs is ready this is the main screen where we need to add controls. Click on Toolbox to get list of .NET controls.

Click on toolbox button

 

Step 4: Inside toolbox click on common controls.

vs with toolbox

 

Step 5: From The toolbox drag and drop the controls ( TextBox, Label, and Button)

Add Controls in VS 2005

 

step 6: now UI is ready and you can run the project and test it. just press F5 to run the project or click on run button.

change The Name of Label in VS 2005

 

Step 7: This is output of our program. Now you have to write login to perform certain operations.

Output

Sponsored Ad

Development Updates