Example of count List Item
<%@ Page Language="C#" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
string s = "Total item of the dropdownlist are<br/>";
s = s + DropDownList1.Items.Count;
string s1 = "Total item of the listbox are <br/>";
s1 = s1 + ListBox1.Items.Count;
Label1.Text = s + "<br/>" + s1;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<strong>HOW TO COUNT LISTITEM IN A DROPDOWNLIST</strong>
<br />
<asp:DropDownList ID="DropDownList1" runat="server" Height="46px" Width="133px">
<asp:ListItem>Item-1</asp:ListItem>
<asp:ListItem>Item-2</asp:ListItem>
</asp:DropDownList>
<br />
<strong>HOW TO COUNT LISTITEM IN A LISTBOX<br />
</strong>
<asp:ListBox ID="ListBox1" runat="server" Height="136px" Width="123px">
<asp:ListItem>ListItem-1</asp:ListItem>
<asp:ListItem>ListItem-2</asp:ListItem>
<asp:ListItem>ListItem-3</asp:ListItem>
<asp:ListItem>ListItem-4</asp:ListItem>
</asp:ListBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Count" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<br />
</div>
</form>
</body>
</html>
Output <!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{
string s = "Total item of the dropdownlist are<br/>";
s = s + DropDownList1.Items.Count;
string s1 = "Total item of the listbox are <br/>";
s1 = s1 + ListBox1.Items.Count;
Label1.Text = s + "<br/>" + s1;
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<strong>HOW TO COUNT LISTITEM IN A DROPDOWNLIST</strong>
<br />
<asp:DropDownList ID="DropDownList1" runat="server" Height="46px" Width="133px">
<asp:ListItem>Item-1</asp:ListItem>
<asp:ListItem>Item-2</asp:ListItem>
</asp:DropDownList>
<br />
<strong>HOW TO COUNT LISTITEM IN A LISTBOX<br />
</strong>
<asp:ListBox ID="ListBox1" runat="server" Height="136px" Width="123px">
<asp:ListItem>ListItem-1</asp:ListItem>
<asp:ListItem>ListItem-2</asp:ListItem>
<asp:ListItem>ListItem-3</asp:ListItem>
<asp:ListItem>ListItem-4</asp:ListItem>
</asp:ListBox>
<br />
<br />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Count" />
<br />
<br />
<asp:Label ID="Label1" runat="server"></asp:Label>
<br />
<br />
</div>
</form>
</body>
</html>
Tidak ada komentar:
Posting Komentar