Search

Monday, September 30, 2013
0 comments

Change ListBox Width Dynamically in ASP.NET

2:02 AMMonday, September 30, 2013
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        ListBox1.Width =int.Parse(ListBox1.SelectedValue);
    }
</script>

<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" AutoPostBack="True"
            onselectedindexchanged="ListBox1_SelectedIndexChanged">
            <asp:ListItem Value="100">Increase 100 pixel</asp:ListItem>
            <asp:ListItem Value="200">Increase 200 pixel</asp:ListItem>
        </asp:ListBox>
    </div>
    </form>
</body>
</html>


Output
Change ListBox Width Dynamically in ASP.NET

Change ListBox Width Dynamically in ASP.NET

Protected by Copyscape Online Copyright Protection Software

0 comments :

Post a Comment

 
Toggle Footer
Top