Introduction
Actually do not want to sum up this aspect of content, found too simple, but in this also fell. So still record it, is to remind oneself, do not despise too much foundation of thing, have this kind of psychology, will carry a big somersault.
An example
Here is a simulation of the most commonly used example, in the list, select Modify, the selected records, shown above, and change the default check in DropDownList.
Way One
Code:
<%@ Page language= "C #" autoeventwireup= true "codebehind=" Default.aspx.cs "inherits=" Wolfy.DropDownListDemo.Default "%> <! DOCTYPE html>
Using System;
Using System.Collections.Generic;
Using System.Linq;
Using System.Web;
Using System.Web.UI;
Using System.Web.UI.WebControls; namespace Wolfy.dropdownlistdemo {public partial class Default:System.Web.UI.Page {protected void Page
_load (object sender, EventArgs e) {dropdownlistprovince.datasource = GetList ();
Dropdownlistprovince.datatextfield = "Name";
Dropdownlistprovince.datavaluefield = "ID";
Dropdownlistprovince.databind ();
Repeaterlist.datasource = GetList ();
Repeaterlist.databind (); } protected list<province> GetList () {list<province> List = new list<province&
gt; (); List.
Add (New Province () {ID = 1, Name = "Beijing", Pid = 0}); List.
Add (New Province () {ID = 2, Name = "Shanghai", Pid = 0}); List.
Add (New Province () {ID = 3, Name = "Henan", Pid = 0}); List. Add (New province () {ID = 4, Name = "Hebei", Pid = 0}); List.
Add (New Province () {ID = 5, Name = "Hunan", Pid = 0}); List.
Add (New Province () {ID = 6, Name = "Hubei", Pid = 0});
return list; } protected void Linkupdate_click (object sender, EventArgs e) {LinkButton link = Sender
As LinkButton;
if (link!= null) {int id = Convert.ToInt32 (link.commandargument); Province Pro = GetList ().
Find (a => a.id = = ID); This. Literalid.text = pro.id.
ToString (); This. Literallevel.text = Pro.
Pid.tostring (); DropDownList's index is zero-based and the ID of the bound data starts at 1, so for the corresponding need to subtract one//change the default check this. Dropdownlistprovince.selectedindex = Pro.
ID-1; }
}
}
}
More Wonderful content: http://www.bianceng.cnhttp://www.bianceng.cn/webkf/aspx/