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

I have below code template in user control & I want check box changed event to be fired when ever i check or uncheck checkbox which is inside datalist & this datalist is intern inside grid view.

Hope for the quick response
<pre lang="xml"><asp:GridView ID="gvSpecification" runat="server" AutoGenerateColumns="false" RepeatLayout="Table"
           OnRowDataBound="gvSpecification_RowDataBound" Width="100%" ItemStyle-CssClass="item-box">
           <Columns>
               <asp:TemplateField>
                   <ItemTemplate>
                       <div class="sub-category-item">
                           <h2 class="category-title">
                               <asp:Label ID="specification" runat="server"></asp:Label>
                           </h2>
                           <div>
                               <asp:DataList ID="dlOption" runat="server" OnItemCommand="dlOption_ItemCommand" RepeatColumns="2"
                                   Width="100%" RepeatDirection="Vertical">
                                   <ItemTemplate>
                                       <asp:CheckBox ID="chkOpt" runat="server" Text='<%# Eval("Name") %>' />
                                   </ItemTemplate>
                               </asp:DataList>
                           </div>
                       </div>
                   </ItemTemplate>
               </asp:TemplateField>
           </Columns>
       </asp:GridView>



Posted

 
Share this answer
 
try to find out in the following way..

C#
protected void repOrder_OnItemCreated_drdFill(object sender, RepeaterItemEventArgs e)
{
  CheckBox chk = (CheckBox)e.Item.FindControl("chkbxOrder");
  chk.CheckedChanged += new EventHandler(CheckedChanged);
}



private void CheckedChanged(object sender, EventArgs e)
      {
        CheckBox cb = (CheckBox)sender;
        try
        {
            My Code
        }
        catch (Exception ex)
        {
        }
}
 
Share this answer
 
Hi

You may try like this

XML
<asp:CheckBox AutoPostBack="true" OnCheckedChanged="chkOpt_Changed" itemId='<%# Container.ItemIndex %>'  ID="chkOpt" runat="server" Text='<%# Eval("Name") %>'  />
.

If you want to access the row where the checkbox included then one way is using the custom attribute as I shown above the ItemId. Other option is through the Parent property.

For example in the check changed event
C#
protected void chkOpt_Changed(object sender, EventArgs e)
 {
     CheckBox chk = (CheckBox)sender;
     //get datalist row id from the custom attribute
     int rowId = Convert.ToInt32(chk.Attributes["itemId"]);

     //get the parent gridview row id through parent hierarchy (in your markup hierarchy)
     GridViewRow row = (GridViewRow)chk.Parent.Parent.Parent.Parent;

     int parentGridRowIndex = row.RowIndex;


 }


Good luck
 
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