Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am unable to set the checksate of the list check box.

I first loaded the items form the database and setthe check state to the selectd one.
the code goes.
chklistbox.SetItemCheck(Index, true);


or

chklistbox.SetItemCheckState(Index, CheckState.Checked);


everything is fine but the error is there is no data at row -1;
i am confused.
anybody with idea...??
Posted

1 solution

this way you can set the selected value of checkbox

 <asp:CheckBoxList ID="CheckBoxList1" runat="server">
            <asp:ListItem Value="0">One</asp:ListItem>
            <asp:ListItem Value="1">Two</asp:ListItem>
            <asp:ListItem Value="2">Three</asp:ListItem>
            <asp:ListItem Value="3">Four</asp:ListItem>
        </asp:CheckBoxList>



CheckBoxList1.SelectedValue = "2"; 

  where "2" should be the value which you want to select.
 


  //if you want to check the selected value fron checkbox you can try 
    foreach (ListItem check in CheckBoxList1.Items)
            {
                if (check.Selected == true)
                {
                    " Your Code"
                }
            }
 
Share this answer
 
v3
Comments
Ankur\m/ 9-May-11 5:41am    
You are assigning index no. to SelectedValue? Are you sure? Moreover you have indicated index as string. And lastly it nowhere answers the question.
Please do not add answers if you do not know.
Mahendra.p25 9-May-11 6:18am    
i think this is fine now

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900