Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Hi all Smile | :)
 
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
 
Vedios:
- 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 Smile | :)
Posted 20-Sep-11 5:42am
Comments
jim lahey at 20-Sep-11 10:58am
   
tried anything at all yet?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
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.
  Permalink  
Comments
Thiyagarajan.rk at 20-Sep-11 11:35am
   
Nice....
archanakumari at 20-Sep-11 23:26pm
   
good
Rate this: bad
good
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) {
		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; }
	}
 

 
}
  Permalink  

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

  Print Answers RSS
0 Afzaal Ahmad Zeeshan 256
1 OriginalGriff 251
2 BillWoodruff 240
3 Maciej Los 230
4 Sergey Alexandrovich Kryukov 195
0 OriginalGriff 6,419
1 Sergey Alexandrovich Kryukov 6,008
2 DamithSL 5,183
3 Manas Bhardwaj 4,673
4 Maciej Los 4,070


Advertise | Privacy | Mobile
Web03 | 2.8.1411019.1 | Last Updated 20 Sep 2011
Copyright © CodeProject, 1999-2014
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