I think such type of problem can be faced easily if you use ListItem eg li li.Value and li.Text Property properly .However I don't know your case.I have attached a simple solution again for you by which you can select the roll number automatically when I check a name from 1st checkboxlist. and vice-versa
In ASPX
<div>
<h3>Select Name </h3>
<asp:checkboxlist id="CheckBoxListName" autopostback="true" onselectedindexchanged="CheckBoxListName_SelectedIndexChanged" runat="server" xmlns:asp="#unknown"></asp:checkboxlist>
<h3>Select Roll</h3>
<asp:checkboxlist id="CheckBoxListRoll" autopostback="true" onselectedindexchanged="CheckBoxListRoll_SelectedIndexChanged" runat="server" xmlns:asp="#unknown"></asp:checkboxlist>
</div>
In .cs(Code behind)
BooksDBEntities db = new BooksDBEntities();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<student> lstStudents = new List<student>();
lstStudents = db.Students.ToList();
foreach (Student s in lstStudents)
{
ListItem li = new ListItem();
li.Text = s.Name;
li.Value = s.Roll;
CheckBoxListName.Items.Add(li);
}
foreach (Student s in lstStudents)
{
ListItem li = new ListItem();
li.Text = s.Roll;
li.Value = s.Roll;
CheckBoxListRoll.Items.Add(li);
}
}
}
protected void CheckBoxListName_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem li in CheckBoxListName.Items)
{
CheckBoxListRoll.Items.FindByValue(li.Value).Selected = li.Selected;
}
}
protected void CheckBoxListRoll_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (ListItem li in CheckBoxListRoll.Items)
{
CheckBoxListName.Items.FindByValue(li.Value).Selected = li.Selected;
}
}
</student></student>