Change ListBox Width Dynamically in ASP.NET

Every control have a width property . In width property you can assign any unit value such as 10, 20 and any other number.If you want to change width of the control at runtime then you must assign width to the ListBox at runtime such as

ListBox1.Width = 20;

If you want to change control width according to listbox item then you must to change Item value to integer.
Lets take an simple example.

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<script runat="server">

    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
        ListBox1.Width =int.Parse(ListBox1.SelectedValue);

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:ListBox ID="ListBox1" runat="server" AutoPostBack="True"
            <asp:ListItem Value="100">Increase 100 pixel</asp:ListItem>
            <asp:ListItem Value="200">Increase 200 pixel</asp:ListItem>

Change ListBox Width Dynamically in ASP.NET

Change ListBox Width Dynamically in ASP.NET


Popular posts from this blog

difference between structure and union in C Language

Difference between Linear search and Binary Search in c language

Difference between static and dynamic websites