ListBox Total information's

  • source
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="listbox18_9.WebForm1" %>

<!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>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <asp:ListBox ID="ListBox1" runat="server" Font-Bold="True" Font-Italic="True" 
            Font-Names="Bahnschrift Light Condensed" Font-Size="Large" ForeColor="#3399FF" 
            Height="100px" SelectionMode="Multiple" Width="100px">
            <asp:ListItem>--Citys--</asp:ListItem>
            <asp:ListItem Value="1">Rajkot</asp:ListItem>
            <asp:ListItem Value="2">Pune</asp:ListItem>
            <asp:ListItem>surat</asp:ListItem>
            <asp:ListItem>delhi</asp:ListItem>
        </asp:ListBox>
        <br />
        <br />
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="submit" />
    
    </div>
    </form>
</body>
</html>


  • code
 using System;

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

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

        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (ListBox1.SelectedIndex == -1)
            {
                Response.Write("<script>alert('pleace select city')</script>");
            }
            else
            {
                foreach (ListItem li in ListBox1.Items)
                {
                    if(li.Selected)
                    
                      {
                         Response.Write("Selected City is  " + li.Text+"<br>");
                      }
                 }

            }
        }

    }
}

  

Comments

Popular posts from this blog

Search Record From Table Using jQuery in Asp.net core MVC

How To insert Radio Button Data in DataBase -- MVC

Toolbox Webparts Controls