Kamis, 03 Oktober 2013

Change DropdownList 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 DropdownList at runtime such as

DropdownList1.Width = 20;

Lets take an simple example.

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

<script runat="server">

    protected voidButton1_Click(object sender, EventArgs e)
    {
        DropDownList1.Width =int.Parse("50");
       
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:DropDownList ID="DropDownList1"runat="server">
            <asp:ListItem>Hyperlink</asp:ListItem>
            <asp:ListItem>CheckBox</asp:ListItem>
            <asp:ListItem>Label</asp:ListItem>
            <asp:ListItem>Panel</asp:ListItem>
        </asp:DropDownList>
        <br />
        <br />
        <asp:Button ID="Button1"runat="server"Text="Change Width"
            onclick="Button1_Click"/>
    </div>
    </form>
</body>

</html>
Output
Change DropdownList Width Dynamically in ASP.NET
Change DropdownList Width Dynamically in ASP.NET


Tidak ada komentar:

Posting Komentar