Click here to Skip to main content
15,918,742 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Friend ,

I am trying to get LableId On CheckboxChange Event which is inside the Datalist Control
But i am not getting it....

Html Code

XML
<asp:DataList runat="server" ID="MaterialList">
                    <ItemTemplate>
                        <asp:Label ID="MaterialId" runat="server" Text='<%# Eval("MaterialId")%>' Visible="false"></asp:Label>
                        <div style="padding-bottom: 5px;">
                            <asp:CheckBox ID="MaterialNameChk" runat="server" Text='<%# Eval("MaterialName")%>' OnCheckedChanged="MaterialNameChk_CheckedChanged" AutoPostBack="true" />
                        </div>
                    </ItemTemplate>
                </asp:DataList>


.cs Code

C#
protected void MaterialNameChk_CheckedChanged(object sender, EventArgs e)
  {
      if (sender != null)
      {
          CheckBox checkbox = (CheckBox)sender;

    DataListItem item = (DataListItem)checkbox.NamingContainer;
            Label idlbl = (Label)item.FindControl("MaterialId");

         // Reset.Text = "Reset";
}
}


Please help me out for this problem...

Thank u In Advance
Posted
Comments
JoCodes 7-Feb-14 1:51am    
Are you able to findcontrol the label (Label)item.FindControl("MaterialId")?

1 solution

Try

protected void MaterialNameChk_CheckedChanged(object sender, EventArgs e)
 {
      if (sender != null)
      {
        CheckBox checkbox = (CheckBox)sender;    
    	if(checkbox != null)
    	{
        Label idlbl = checkbox.Parent.FindControl("MaterialId") as Label;

    	}
   }
}
 
Share this answer
 
Comments
Karthik_Mahalingam 7-Feb-14 2:05am    
Hi JoCodes,
I guess it will work on Parent.Parent , since the check box parent is Div and div's Parent is the datalist item...
Label idlbl = checkbox.Parent.Parent.FindControl("MaterialId") as Label;
just check once...
JoCodes 7-Feb-14 2:28am    
Thanks Karthik . I just cross checked the same code with checkbox.Parent.GetType()and it returns Datalist type with single Parent? If div had runat= server then would have an issue.But really appreciate the point. :)
Karthik_Mahalingam 7-Feb-14 2:32am    
Thanks for the info

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