Custom Search

Tuesday, May 27, 2008

Using Drop Down List in ASP.NET

The DropDownList control enables you to display a list of options while requiring a minimum of screen real estate. A user can select only one option at a time when using this control

Code example :
< %@ Page Language="VB" %>
< !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
< script runat="server">

Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
lblStudent.Text = ddlStudent.SelectedItem.Text
End Sub
< /script>
< html xmlns="http://www.w3.org/1999/xhtml" >
< head id="Head1" runat="server">
< title>Show DropDownList< /title>
< /head>
< body>
< form id="form1" runat="server">
< div>

< asp:DropDownList
id="ddlStudent"
DataSourceID="srcstudent"
DataTextField=name"
DataValueField="id"
Runat="server" />

< asp:Button
id="btnSubmit"
Text="Submit"
OnClick="btnSubmit_Click"
Runat="server" />

< hr />

< asp:Label
id="lblStudent"
Runat="server" />

< asp:SqlDataSource
id="srcstudent"
SelectCommand="SELECT id,name FROM student"
ConnectionString="<%$ ConnectionStrings:student %>"
Runat="server" />

< /div>
< /form>
< /body>
< /html>

The DropDownList control renders an HTML <> tag. One problem with the HTML <> tag is that it has an infinite z index. In other words, you can't place other objects, such as an absolutely positioned <> tag, in front of a DropDownList control in a page.

No comments:

Free Traffic

 Join My Community at MyBloglog! Blog Flux Directory 

Web Developement Blogs - BlogCatalog Blog Directory web development blog  Internet Blogs - Blog Top Sites 

Blog Directory 

Click Here for Free Traffic!

Link2Communion.com