Click here to Skip to main content
13,003,589 members (59,272 online)
Rate this:
Please Sign up or sign in to vote.
Hi all :)

I have a SQLData source, connected to listbox as a wizard

I want to retrieve some data when I choose an item

suppose here is my table

- Video ID
- Video Name
- Video Path

I want to ( for example ) to retrieve the name and the path when I choose an Item inside my listbox and set it as a text in atextbox

how can I do that ?

thank you all :)
Posted 20-Sep-11 4:42am
jim lahey 20-Sep-11 10:58am
tried anything at all yet?
Rate this: bad
Please Sign up or sign in to vote.

Solution 1


Here 'm providing my code for showing data in textbox when selection changed in listbox

protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    MylocalDataClassesDataContext db = new MylocalDataClassesDataContext();
    var h = from g in db.VideoTabs
            where g.vid == int.Parse(ListBox1.SelectedValue)
            select g;
    foreach (VideoTab vt in h)
        TextBox1.Text ="The Vid of selected Item is "+ vt.vid + " and Video Name is     " + vt.vname;

Here I used Linq for retrieving data from database.

And onemore thing is you've to set autopostback to true for ListBox control by default it is false
All the Best.
Thiyagarajan.rk 20-Sep-11 11:35am
archanakumari 20-Sep-11 23:26pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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) {

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";
	return listOfVideoAndPaths;

private void LoadDropDown()
	this.ddlVideoList.DataTextField = "VideoName";
	this.ddlVideoList.DataValueField = "VideoPath";
	this.ddlVideoList.DataSource = CreateVideoData();
	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; }


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170626.1 | Last Updated 20 Sep 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100