Click here to Skip to main content
15,886,809 members
Please Sign up or sign in to vote.
2.00/5 (2 votes)
See more:
Hi all,

I have a datalist in which I took three check boxes contain
1. user name
2. read rights(visibilty false)
3. write rights(visibilty false)
I bind them to data base.
Now I want that when the username checkbox is checked then read and write checkboxes are visible true.

Here is the design code:


XML
<td>
                                               <table id="complicated">
    <asp:DataList GridLines="Both" BorderStyle="Solid" ID="dList1" runat="server"
            OnItemDataBound="dList1_ItemDataBound"
            OnSelectedIndexChanged="dList1_SelectedIndexChanged" oneditcommand="dList1_EditCommand"
                                                       onitemcommand="dList1_ItemCommand" onitemcreated="dList1_ItemCreated" >
        <ItemTemplate>
        <table =" border-style:solid;" style="width: 484px">
        <tr>
            <td>
            <asp:Label ID="lblId" runat="server" Text='<%# Eval("id") %>' Visible="False"></asp:Label>
            </td>
            <td class="style14">
                <asp:CheckBox ID="cboxPermission1" runat="server"
                    text='<%# Eval("username") %>' AutoPostBack="True"
                    oncheckedchanged="cboxPermission1_CheckedChanged"  />
            </td>
            <td style="overflow:scroll;height:0px; width:100%;">
                <asp:CheckBox ID="cboxPermission2" runat="server" Text="Read"
                    Visible="False"  />
            </td>
            <td style="overflow:scroll;height:0px; width:100%;">
                <asp:CheckBox ID="cboxPermission3" runat="server" Text="Write"
                    Visible="False" />
            </td>
        </tr>
        </table>

        </ItemTemplate>
        </asp:DataList>
         </table></td>



I did not understand how I can set visibility to true on checkchanged of username's checkbox.

Please help
Posted
Updated 18-Nov-10 17:58pm
v2
Comments
Sunasara Imdadhusen 19-Nov-10 4:18am    
Please check updated answer and please do let me know if issue going on...

You can do this by either use of jQuery or DataList.ItemCreated event, if you use jquery then traverse table which is generated from DataList and get the value of username and accordingly that set visibility of read rights and write rights checkbox, if use DataList.ItemCreated event then get value of username checkbox by
Dim userName As CheckBox = _
CType(e.Item.FindControl("cboxPermission1"), CheckBox)
After get checkbox get it value by using it's property "Checked" and accordingly it's value set visibility of read rights and write rights checkbox visibility with same syntax, I hop this is enough
 
Share this answer
 
Comments
sharmarun 19-Nov-10 0:45am    
yah i done that easily but i want it on check changed event
when checked changed then visibility true
Sunasara Imdadhusen 19-Nov-10 1:16am    
you can achieve using my answer, and this is done at client side so it's reducing server trip.
sharmarun 19-Nov-10 1:44am    
thanxz i got dat
sharmarun 19-Nov-10 1:48am    
what read and write checkboxes not shown
Sunasara Imdadhusen 19-Nov-10 4:24am    
Please check updated answer and please do let me know if issue going on...
Hi Arun,

Updated Answer is:
MIDL
document.getElementById(Read).style.display = visible ;
          document.getElementById(Write).style.display = visible ;



This is complete solution:

write in .cs file
C#
protected void dList1_ItemDataBound(object sender, DataListItemEventArgs e)
   {
       CheckBox chkPermission = (CheckBox)e.Item.FindControl("cboxPermission1");
       CheckBox chkRead = (CheckBox)e.Item.FindControl("cboxPermission2");
       CheckBox chkWrite = (CheckBox)e.Item.FindControl("cboxPermission3");
       chkPermission.Attributes.Add("onclick", "showhideReadWrite(this,'" + chkRead.ClientID + "','" + chkWrite.ClientID + "');");
   }

write in .aspx file between <head></head> tag
XML
<head>
<script language="javascript" type="text/javascript">
       function showhideReadWrite(_this, Read, Write) {
           var visible = (_this.checked) ? '' : 'none';
           document.getElementById(Read).style.display = visible ;
           document.getElementById(Write).style.display = visible ;
       }
   </script>
</head>



Please do let me know, if you have any doubt.

Please provide "Vote":thumbsup: if this would be helpful, and make "Accept Answer" if this would be correct answer.:rose:

Thanks,
Imdadhusen
 
Share this answer
 
v3
Comments
sharmarun 19-Nov-10 1:21am    
i will explain to u

let us suppose our datalist is created with check boxes where read and write checkbboxes are false

now i want that when i check a perticular checkbox in datalist then corresponding read and write checkboxes's visibilty is true

i think these are done at cboxpermission1's checked changed event

so here i need ur help
plz provide sum help
Sunasara Imdadhusen 19-Nov-10 1:23am    
will you tried my answer?
sharmarun 19-Nov-10 1:37am    
yah i got dat sorry

thanxz a lot
Sunasara Imdadhusen 19-Nov-10 1:42am    
Thanks,
sharmarun 19-Nov-10 1:52am    
what read and write checkboxes not shown

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