How to Validate Two listboxes
I have two Listbox and have same items in both listbox but i want to save items in one listbox not be saved in databsae from another listbox
5 Answers
Know the answer? Post it. Somebody with the same question will find it here.


Sanjeeb LenkaRank #301 · 8.3K reputationPosted Oct 3, 2013, 11:06 PM EDT
i didn't get your point. plz provide more details.
Khargesh RajputRank #616 · 3.9K reputationPosted Oct 3, 2013, 11:20 PM EDT
on btclick listbox1 and listbox2 items not to be same
Khargesh RajputRank #616 · 3.9K reputationPosted Oct 3, 2013, 11:34 PM EDT
int i, j;
for (i = 0; i <= listtrainee.Items.Count - 1; i++)
{
for (j = 0; j <= Listtrainne_ab.Items.Count - 1; j++)
{
//foreach (ListItem lst1 in listtrainee.Items)
//{
// foreach (ListItem lst2 in Listtrainne_ab.Items)
// {
if (listtrainee.Items[i].Value == Listtrainne_ab.Items[j].Value)
// if (empoyee.Split(',')[0].ToString() == empoyee_ab.Split(',')[0].ToString())
{
lblMsg.Text = "Present and Absent Employee Should Not Be Matched";
// ClientScript.RegisterStartupScript(Page.GetType(), "", "");
}
else
{
int execount = objdal.ExecuteNonQuery(CommandType.Text, strQuery, hsInput);
if (execount > 0)
{
}}}}
but there is saved data at each loop
Khargesh RajputRank #616 · 3.9K reputationPosted Oct 4, 2013, 12:33 AM EDT
thanks
Sanjeeb LenkaRank #301 · 8.3K reputationPosted Oct 4, 2013, 1:21 AM EDT
you can use like this
for (int i = 0; i < listtrainee.Items.Count; i++)
{
if (Listtrainne_ab.Items.Contains(listtrainee.Items[i]))
{
lblMsg.Text = "Present and Absent Employee Should Not Be Matched";
}
}