Showing posts with label asp.net record. Show all posts
Showing posts with label asp.net record. Show all posts

Wednesday, 3 August 2016

write a program to print selected value of listbox in asp.net

listbox.aspx.cs

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="listbox.aspx.cs" Inherits="our_program.listbox" %>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<center><h1>LIST BOX AND SELECTED VALUE</h1></center>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <center>
    <div>
               <asp:ListBox ID="blt" runat="server" Height="169px" Width="118px" ></asp:ListBox>
        <br />
        <asp:Button ID="btn" runat="server" Text="Button" onclick="btn_Click" />
        <br />
        <asp:Label ID="lbl" runat="server" Text="selected value is shown here"></asp:Label>
    
    </div>
    </center>
    </form>
</body>
</html>

listbox.aspx.cs

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

namespace our_program
{
    public partial class listbox : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            blt.Items.Add("JAN");
            blt.Items.Add("FEB");
            blt.Items.Add("MAR");
            blt.Items.Add("APR");
            blt.Items.Add("MAY");
            blt.Items.Add("JUN");
            blt.Items.Add("JUL");
            blt.Items.Add("AUG");
            blt.Items.Add("SEP");
            blt.Items.Add("OCT");
            blt.Items.Add("NOV");
            blt.Items.Add("DEC");
        }

        protected void btn_Click(object sender, EventArgs e)
        {
            lbl.Text = "YOU ARE SELECTED MONTH IS :" + blt.SelectedItem.ToString();
        }
    }
}

write asp.net program to print textbox value when a change occur in textbox

textbox_with_label.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="textbox_with_label.aspx.cs" Inherits="our_program.textbox_with_label" %>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<center>
<h1> TEXTBOX WITH LABEL</h1>
</center>
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <center>
    <div>
    <asp:TextBox runat="server" ID="txt" OnTextChanged="textchanged" AutoPostBack="true"></asp:TextBox>
    <br />
    <asp:Label runat="server" ID="lbl" Text="textbox value"></asp:Label>
    </div>
    </center>
    </form>
</body>
</html>

textbox_with_label.aspx.cs

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

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

        }
        protected void textchanged(object sender, EventArgs e)
        {
            string a = txt.Text;
            lbl.Text = a.ToString();
        }
    }
}

write asp.net program to print value of radio button when button is clicked

radio_button.aspx


<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="radio_button.aspx.cs" Inherits="our_program.radio_button" %>

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

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
             <center><h1>radio button</h1></center>
</head>
<body>
    <form id="form1" runat="server">
    <center>
    <div>
        <asp:RadioButton ID="rbn1" runat="server" GroupName="radio"  Text="first radio button" />
        <br />
        <asp:RadioButton ID="rbn2" runat="server" GroupName="radio"  Text="second radio button"/>
        <br />
        <asp:RadioButton ID="rbn3" runat="server" GroupName="radio"  Text="third radio button"/>
        <br />
        <asp:Button ID="btn" runat="server" Text="Button" onclick="Button1_Click" />
        <br />
        <asp:Label ID="lbl" runat="server" Text="selected text will shown here"></asp:Label>
    </div>
    </center>
    </form>
</body>
</html>


radio_button.aspx.cs

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

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

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (rbn1.Checked == true)
            {
                lbl.Text = "Your selected radio button is : " + rbn1.Text;
            }
            if (rbn2.Checked == true)
            {
                lbl.Text = "Your selected radio button is : " + rbn2.Text;
            }
            if (rbn3.Checked == true)
            {
                lbl.Text = "Your selected radio button is : " + rbn3.Text;
            }
        }
    }
}