Académique Documents
Professionnel Documents
Culture Documents
The basic ASP.NET flow here is (using 2.0 here, but works similarly in
1.1 using DataGrid):
1) Create a GridView with a bound column for state and a template
column for the DropDownList
2) Create a label to display the city name upon selecting it in the
DropDownList.
3) Bind the GridView to an array of state objects (could be bound to
many other things as well, but keeping it simple for this example).
State contains properties for Name and for Cities.
4) Hookup RowCreated event on the GridView so that we can populate
the cities into the particular row's DropDownList.
5) Add postback event for getting the selected city and populating the
label with it.
string[] cities =
new string[] { "Portland", "Salem", "Eugene" };
State state = new State("OR", cities);
states.Add(state);
cities =
new string[] { "Seattle", "Tacoma", "Olympia" };
state = new State("WA", cities);
states.Add(state);
this.gvStates.DataSource = states;
this.gvStates.DataBind();
}
}
This code should be more defensive with null checking, type checking
and exception handling in place. But, you get the idea of the general
work flow (and now, so do I).