ConfigurationDAL dAL = new ConfigurationDAL();
DataTable dt = new DataTable();
if(drp_Volunteeer.SelectedValue !=null)
{
dt = dAL.FetchVolunteerDetails(volunteerID: drp_Volunteeer.SelectedIndex).Tables[0];
foreach (DataRow dr in dt.Rows)
{
txt_FirstName.Text = dr["firstname"].ToString();
txt_fatherName.Text = dr["fathername"].ToString();
}
}
SelectedValue count shows 32:
SelectedIndex works fine:
Filling the TextBox is not working.
When I User Select Data Can't Revtive Data From DataBase:
I don't know how you can fill (add) data to SelectedBox
. But you maybe know, SelectedBox's Items supports any object, you can add any objects to items. I usually create my custom class for filling SelectedBoxs. For Example, you can create Volunteeer
class for adding, and viewing data on the SelectedBox. Example:
public class Volunteeer
{
private int id;
private string firstname;
private string lastname;
public Volunteeer(int pid, string fname, string lname)
{
id = pid;
firstname = fname;
lastname = lname;
}
public string GetFirstName()
{
return firstname;
}
public string GetLastName()
{
return lastname;
}
public int GetId()
{
return id;
}
public override string ToString()
{
return firstname + ' ' + lastname;
}
}
Method ToString()
are for viewing text data format on the SelectedBox. After then you can very easily get selected items. Example:
private void SelectedText_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (SelectedText.SelectedIndex >= 0)
{
txtFirstName.Text = (SelectedText.SelectedValue as Volunteeer).GetFirstName();
txtLastName.Text = (SelectedText.SelectedValue as Volunteeer).GetLastName();
}
}
And this is a sample how you can fill data to SelectedBox:
SelectedText.Items.Add(new Volunteeer(1, "Sara", "Montano"));
SelectedText.Items.Add(new Volunteeer(2, "Jon", "Smith"));
SelectedText.Items.Add(new Volunteeer(3, "Tom", "Serato"));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.