Immediate help requred-Populating CheckBoxList from saved data [Resolved]

Posted by Sina under ASP.NET on 7/6/2012 | Points: 10 | Views : 1057 | Status : [Member] | Replies : 1
Hi guys i need a help. I have a checkboxlist and a related table. Now once user registers for the first time, he will be checking items of the checkboxlist and i want those items to be checked when the user logs in again.
Hope i am clear.I have written the code below but its not working. It was just a try. So pl help me.

SqlDataReader drr = command.ExecuteReader();
if(drr.Read()==true)
{

ListItem li = chkCat.Items.FindByText(drr[0].ToString());
if (li != null)
{
li.Selected = true;
}

}

'li' is always showing null. I feel its a small correction but not able to get where..pl help.

@Sina


Responses

Posted by: Sina on: 7/6/2012 [Member] Starter | Points: 25

Up
0
Down

Resolved
Got it!! Hers the solution (it worked for me :) )
SqlDataReader drr = command.ExecuteReader();

while (drr.Read())
{


ListItem li = chkCat.Items.FindByValue(drr["CatName"].ToString());
if (li != null)
{
li.Selected = true;
}


}



@Sina

Sina, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response