Click here to Skip to main content
15,895,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
heyy...

I have a datalist, Inside that datalist I have checkbox that loaded dynamically in datalist..

Also I load the corresponding textbox(visible =false) of checkbox ...

I want a jquery visible the corresponding textbox when the checkbox is checked....


In datalsit each one have different id...So I can't write the jquery....Any Idea??

here is my code :-


XML
<asp:DataList ID="dtEmpCategory" runat="server" RepeatDirection="Horizontal" RepeatColumns ="8">
     <ItemTemplate><div  id="boxcolcb" >
      <p>
          <asp:CheckBox ID="ChkEmployee" runat="server" CssClass="abc"
              Text= '<% #Eval("EmployeeCategoryName") %>' />

       </p>
         <p>
          <asp:TextBox ID="txtEmployeeIncentive" runat="server" MaxLength="7"
                ondrop="return false" placeholder="Up to 7 digits"
                   attr-identity="txtEmployeeIncentive" onpaste="return false" oncut="return false"
                   style="display:none;"></asp:TextBox>
         </p>
         </div>    </ItemTemplate>
      </asp:DataList>
Posted

your check box id should be unique
XML
<asp:DataList ID="dtEmpCategory" runat="server" RepeatDirection="Horizontal" RepeatColumns ="8">
     <ItemTemplate><div  id="boxcolcb" >
      <p>
          <asp:CheckBox ID="ChkEmployee" runat="server" CssClass="abc"
              Text= '<% #Eval("EmployeeCategoryName") %>' oncheck="fun(this.id)" />

       </p>
         <p>
          <asp:TextBox ID="txtEmployeeIncentive" runat="server" MaxLength="7"
                ondrop="return false" placeholder="Up to 7 digits"
                   attr-identity="txtEmployeeIncentive" onpaste="return false" oncut="return false"
                   style="display:none;"></asp:TextBox>
         </p>
         </div>    </ItemTemplate>
      </asp:DataList>

JavaScript
<script type="text/javascript">
function fun(id)
{
id="<%="+id+".ClientID%>"
$(id).attr("display", "block");
}
</script>
 
Share this answer
 
v3
Comments
aravindnass 30-Jul-13 2:30am    
I got error -
: 'string' does not contain a definition for 'ClientID' and no extension method 'ClientID' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
Member 9762654 30-Jul-13 3:26am    
definition of fun should be in client side check my updated solution
aravindnass 30-Jul-13 5:06am    
but I got the same error.....
<script language="javascript" type="text/javascript">

    $(document).ready(function() {

        $("input[type=checkbox][id*=ChkEmployee]").change(function() {

            if ($("input[type=checkbox][id*=ChkEmployee]").is(":checked")) {


                calculateTotal($(this));

            }
            else {
                checkfalse($(this));
            }



        });

        function calculateTotal(current) {




            current.closest("tr").find("input[type=text][id*=txtEmployeeIncentive]").show();


        }
        function checkfalse(current) {


            current.closest("tr").find("input[type=text][id*=txtEmployeeIncentive]").hide();

        }
    });
   </script>
 
Share this answer
 

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