Can anybody correct my codes?
I populated a listbox with emails(String).
how do i retrieve the emails from the listbox and store the emails into a studentArray??
string[] studentArray = new string[];
foreach (ListItem email in lbxMpgroup.Items)
{
lblStudent.Text += email.Text + "
";
for (int i = 0; i < studentArray.Length; i++)
{
studentArray[i] = email.Text;
}
}
//When i run the above code, only the first email is stored in the array....
Thanks! =)
Jan MontanoPosted Aug 15, 2007, 6:19 AM
For example:
string student = "Mike Gold";
string email = "[email protected]";
string record = student + " - " + email;
//lbxMpgroup.Items.Add(student + " - " + email); // value will be "Mike [email protected]"
string[] temparray = record.Split('-');
// temparray[0] will contain "Mike Gold" while temparray[1] will contain "[email protected]"
Also, please have a look for ListView control for an alternative.
ezekiel wongPosted Aug 15, 2007, 5:15 AM
Hi Mr Jan Montano,
Thanks for sharing your code, my program can run successfully. =)
Now, i have to make my program more user friendly.
Do u have any idea how i could populate a listbox with more than 2 items?
for my current listbox, it only display the student email.
if (!IsPostBack)is it possible that i display both the student email and student name, yet add only the email to the studentArray?
{
object[] student =; foreach (string s in student){
lbxStudent.Items.Add(s);
}
}
Jan MontanoPosted Aug 15, 2007, 1:24 AM
string[] studentArray = new string[lbxMpgroup.Items.Count];
for (int i = 0; i < lbxMpgroup.Items.Count; i++)
{
}