Wednesday, July 16, 2014
In part one DropDownList Part 1: Bind a DataTable to A DropDownList we learned how to bind a DataTable to a DropDownList. In this tutorial we will learn to set the default value of the DropDownList control on the page's first load that is before there is a post back to the page. This behavior is commonly used when you want to default the drop down list to a particular selection. Such as the "United States" in a list of countries drop down list.
To set a default value in the DropDownList control follow the steps below.
1. Add the SetDefaultSelectItem method to the code behind file.
2. Add a condition to only set the default value on the first page load
To set a default value in the DropDownList control follow the steps below.
1. Add the SetDefaultSelectItem method to the code behind file.
protected void SetDefaultSelectItem(string txtSelect) { DropDownList1.Items.FindByText(txtSelect).Selected = true; }
2. Add a condition to only set the default value on the first page load
protected void Page_Load(object sender, EventArgs e) { if(!Page.IsPostBack) { BindCategoriesList(); SetDefaultSelectItem("Seafood"); } }3. If you run the application you will now see that "Seafood" is the default selection on the DropDownList control, when the page first load
Related Blogs:
- Bind a DataTable To A DropDownList
- (DropDownList) Setting Default Value on First Page Load
- Use The DropDownList Control To Populate GridView
- Bind DropDownList To A List Of Objects
Subscribe to:
Post Comments (Atom)
Search This Blog
Tags
Web Development
Linux
Javascript
DATA
CentOS
ASPNET
SQL Server
Cloud Computing
ASP.NET Core
ASP.NET MVC
SQL
Virtualization
AWS
Database
ADO.NET
AngularJS
C#
CSS
EC2
Iaas
System Administrator
Azure
Computer Programming
JQuery
Coding
ASP.NET MVC 5
Entity Framework Core
Web Design
Infrastructure
Networking
Visual Studio
Errors
T-SQL
Ubuntu
Stored Procedures
ACME Bank
Bootstrap
Computer Networking
Entity Framework
Load Balancer
MongoDB
NoSQL
Node.js
Oracle
VirtualBox
Container
Docker
Fedora
Java
Source Control
git
ExpressJS
MySQL
NuGet
Blogger
Blogging
Bower.js
Data Science
JSON
JavaEE
Web Api
DBMS
DevOps
HTML5
MVC
SPA
Storage
github
AJAX
Big Data
Design Pattern
Eclipse IDE
Elastic IP
GIMP
Graphics Design
Heroku
Linux Mint
Postman
R
SSL
Security
Visual Studio Code
ASP.NET MVC 4
CLI
Linux Commands
Powershell
Python
Server
Software Development
Subnets
Telerik
VPC
Windows Server 2016
angular-seed
font-awesome
log4net
servlets
tomcat
AWS CloudWatch
Active Directory
Angular
Blockchain
Collections
Compatibility
Cryptocurrency
DIgital Life
DNS
Downloads
Google Blogger
Google Chrome
Google Fonts
Hadoop
IAM
KnockoutJS
LINQ
Linux Performance
Logging
Mobile-First
Open Source
Prototype
R Programming
Responsive
Route 53
S3
SELinux
Software
Unix
View
Web Forms
WildFly
XML
cshtml
githu
Đặt vé máy bay tại Aivivu, tham khảo
ReplyDeleteVe may bay di My
mua vé máy bay về việt nam từ mỹ
ve may bay tư duc ve viet nam
cách mua vé máy bay từ nhật về việt nam
gia ve may bay vietjet tu han quoc ve viet nam
khi nào có chuyến bay từ canada về việt nam
chuyến bay dành cho chuyên gia