Click here to Skip to main content
16,020,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I Have one table Table1 which have 4 field TView,TRead,TUpdate,TDelete integer type.
these field store 1 or o .


XML
<asp:CheckBoxList ID="chkEmplyeeMaster" runat="server"
                          RepeatDirection="Horizontal" CssClass="chkclass">
                      <asp:ListItem Value="1">View</asp:ListItem>
                      <asp:ListItem Value="2">Read</asp:ListItem>
                      <asp:ListItem Value="3">Update</asp:ListItem>
                      <asp:ListItem Value="4">Delete</asp:ListItem>
                      </asp:CheckBoxList>



when any chekbox cheked then its store 1 in Sql table.

Now I have these Above column all value is 1 i need to edit checkboxlist value .
how can i populate chekboxlist from these 4 field value ,when value is 1 then checked otherwise at 0 value its show uncheck.

please help me .......................
thanks
Posted

1 solution

Hi
Try to change the checkbox list like this
XML
<asp:CheckBoxList ID="chkEmplyeeMaster" runat="server"
                          RepeatDirection="Horizontal" CssClass="chkclass">
                      <asp:ListItem Text="View"></asp:ListItem>
                      <asp:ListItem Text="Read"></asp:ListItem>
                      <asp:ListItem Text="Update"></asp:ListItem>
                      <asp:ListItem Text="Delete"></asp:ListItem>
                      </asp:CheckBoxList>


Just create a common function like this
C#
private void SetCheckBoxListSelection(CheckBoxList cbxlist,string OptionName, bool Value)
    {
        var item=cbxlist.Items.Cast<ListItem>().Where(li => li.Text.ToLower().Equals(OptionName.ToLower())).FirstOrDefault();
        if (item != null) item.Selected = Value;
    }


Then call this function
by passing the
SetCheckBoxListSelection(chkEmplyeeMaster,"View",TView==1?true:false);
 
Share this answer
 
Comments
mohd vaquas 20-Jun-11 6:58am    
Thanks sir Its Working .........................
NDebata 20-Jun-11 7:13am    
you are welcomed

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