I would try this. The CreateData would be your SQLDataSource
set the video path as the datavalue and the video name as the datatextfield
Be sure that you have auto postback set to true on the dropdown and set the text box text when the drop down selection is changed.
protected void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack) {
LoadDropDown();
}
}
private List<VideosAndPaths> CreateVideoData()
{
List<VideosAndPaths> listOfVideoAndPaths = new List<VideosAndPaths>();
VideosAndPaths newVAP = default(VideosAndPaths);
for (i = 0; i <= 10; i++) {
newVAP = new VideosAndPaths();
newVAP.VideoID = i;
newVAP.VideoName = "Video #" + i.ToString;
newVAP.VideoPath = "C:\\MyVideos\\" + newVAP.VideoName + ".avi";
listOfVideoAndPaths.Add(newVAP);
}
return listOfVideoAndPaths;
}
private void LoadDropDown()
{
this.ddlVideoList.DataTextField = "VideoName";
this.ddlVideoList.DataValueField = "VideoPath";
this.ddlVideoList.DataSource = CreateVideoData();
this.ddlVideoList.DataBind();
ListItem li = new ListItem("select Video", "-1");
li.Selected = true;
this.ddlVideoList.Items.Insert(1, li);
}
protected ddlVideoList_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.ddlVideoList.SelectedValue != "-1") {
this.txtVideoPath.Text = this.ddlVideoList.SelectedValue;
} else {
this.txtVideoPath.Text = "";
}
}
public class VideosAndPaths
{
private int _videoID;
public int VideoID {
get { return _videoID; }
set { _videoID = value; }
}
private string _videoName;
public string VideoName {
get { return _videoName; }
set { _videoName = value; }
}
private string _videoPath;
public string VideoPath {
get { return _videoPath; }
set { _videoPath = value; }
}
}