I’m fairly new to .NET and I’m finding it a challenge locating solutions for some problems I was having. I decided to start writing down the solutions I found or created. There might be better ways to solve the problems. If you find a better way please let me know.
Now on the problem. To start off the application is written in VB.NET 2.0. There is a form with a asp dropdown control that I needed to set the datasource. This dropdown control lives inside a asp repeater control. I wanted to set the datasource inside an expression like the following:
The code behind would have a function that creates a DataTable and returns it to be used as the datasource. The DataTable would have two columns, MyText and MyValue, which would be used for the name and value for the dropdownlist control.
The issue was binding the name (what is visibly displayed) and value to be used in the dropdown control. I couldn’t do this in the function above becuase it’s job is to return a datasource and I didn’t have a reference to the dropdown control. There are events you can hook into for the dropdownlist control like OnInit where you can do this but I was hesitant becuase there didn’t seem to be a way to pass paramters. Finally I found you can bind the name and value within the markup!
This worked perfectly and I liked how I can set values within the markup of the control.