This situation often occurs. The DropDownList control is mostly used to bind database data, but it is often required to display non-database data on the page, for example, "Please select" "All XX" and so on. The method to implement this function is simple and not simple. I will not say much about it. Let's look at the source code directly!
Assume that the database and fields to be bound have been created and determined.
The code for binding database fields is not specifically written. Suppose I write it in the bindList () method of a class named "Info" --> Info. cs class.
Below is the source code
Using System;
Using System. Collections;
Using System. ComponentModel;
Using System. Data;
Using System. Drawing;
Using System. Web;
Using System. Web. SessionState;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. HtmlControls;
Using System. Text. RegularExpressions;
Namespace Client. Page. ClientInfo
{
/// <Summary>
/// Add abstract description.
/// </Summary>
Public class Add: System. Web. UI. Page
{
Protected Classes. ClientInfo myClass = new Client. Classes. ClientInfo ();
Protected System. Web. UI. WebControls. DropDownList DropDownList1;
Private void Page_Load (object sender, System. EventArgs e)
{
If (! This. IsPostBack)
{
This. BindGrid ();
// This. BindCode ();
}
// Place user code here to initialize the page
}
# Code generated by region Web form designer
Override protected void OnInit (EventArgs e)
{
//
// CODEGEN: This call is required by the ASP. NET Web form designer.
//
InitializeComponent ();
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service