Repeater with checkboxes

(ASP.NET)


Hi,
In this article i placed checkbox inside the repeater control. On the click of checkbox i hide and show the textbox, which is present inside the repeater control.

.aspx page

<head runat="server">
  <script type="text/javascript" src="../Scripts/jquery-1.9.1.js"></script>
    <title></title>
<script type="text/javascript">
    
        $(function () {
            $('input[id^="rptr_products_chck_productid"]').change(function () {

                if ($(this).is(":checked")) {

                    $(this).closest("td").next().find("input").show(); //set visible property to true
                 
                }
                else {
                  
                    $(this).closest("td").next().find("input").hide();//set visible property to false
                }

            });
        });

    </script>

</head>


<div>
  <asp:Repeater OnItemDataBound="rptr_products_ItemDataBound"  id="rptr_products" runat="server">

  <HeaderTemplate>
<table border="1" width="100%">
<tr>
<th>Product ID</th>
<th>product Name</th>
</tr>
</HeaderTemplate>

<ItemTemplate>
<tr>
 <td><asp:CheckBox ID="chck_productid" runat="server" Text='<%#Eval("ProductID")%>' /></td>
<td><asp:TextBox ID="txt_productname" style="display:none" runat="server" Text='<%#Eval("ProductName")%>' /></td>
</tr>
</ItemTemplate>


<FooterTemplate>
</table>
</FooterTemplate>

</asp:Repeater>
    </div>


Codebehind file:-

  protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    bindRepeater();
                }
            }
            catch (Exception)
            { }
        }

        private void bindRepeater()
        {
            try
            {

                SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["Northwindconstring"].ToString());

                string query = "select * from Products";

                DataSet ds = new DataSet();

                SqlDataAdapter sqldt = new SqlDataAdapter(query, sqlcon);
                sqldt.Fill(ds);

                rptr_products.DataSource = ds;
                rptr_products.DataBind();
            }
            catch (Exception)
            { }
        }

Image

Ratings


Average Rating: 0.00 by 0 users
Giri Prasad
6/20/2013
6/20/2013
Download PDF

Comments