Click here to Skip to main content
16,010,022 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i will use checkbox control in repeater.

i have to find the value of checkbox when it is checked.

i have do checkbox checked event for this,but event do not Execute.the control always goes outside the checked event.

What I have tried:

<asp:Repeater ID="rptrrol" runat="server">
<itemtemplate>


<asp:Label ID="lblrid" Text='<%#Eval("rid") %>' Visible="false" runat="server">
<asp:CheckBox ID="chkrole" runat="server" Text='<%#Eval("role") %>' OnCheckedChanged="chkrole_CheckedChanged" AutoPostBack="true" />






C# code

private void role()
{
DataTable dt1 = new DataTable();
dt1 = objRoleBL.Select_Role();
if (dt1.Rows.Count > 0)
{
rptrrol.DataSource = dt1;
rptrrol.DataBind();
}
}
protected void chkrole_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
RepeaterItem item = (RepeaterItem)chk.NamingContainer;
Label lblCampCode = (Label)item.FindControl("lblrid");
string CampCode = lblCampCode.Text;
}
Posted
Updated 17-Jul-16 19:36pm
Comments
Karthik_Mahalingam 18-Jul-16 3:27am    
make sure you are binding the data inside !page.ispostback
Vibhusha Devani 18-Jul-16 3:38am    
Ya it will be bind on !ispostback....,Actually the ckeckbox data are bind by repeater data control.and now i have to get a checkbox checked value.that will be insert on other table of database.

The data on repeater getting was correct.but when i want to checked the check event of checkbox and try to get value of checkbox the event can't exicuted.the control can't goes on checkbox checked event.

1 solution

Put the CheckBox and Label control inside ItemTemplate . The content of this template will be repeated for each record present in its DataSource
Try
<asp:repeater id="rptrrol" runat="server" xmlns:asp="#unknown">
 <itemtemplate>
    <asp:label id="lblrid" text="<%#Eval("rid") %>" visible="false" runat="server"></asp:label>
    <asp:checkbox id="chkrole" runat="server" text="<%#Eval("role") %>">
    OnCheckedChanged="chkrole_CheckedChanged" AutoPostBack="true" /> 
</asp:checkbox>
</itemtemplate>
</asp:repeater>


Thanks
 
Share this answer
 
v2
Comments
Vibhusha Devani 18-Jul-16 2:23am    
See, Both controls are inside the Itemtemplate.still event not exicuted.
Animesh Datta 18-Jul-16 2:50am    
http://www.codeproject.com/Articles/17953/ASP-NET-CheckBox-Command-in-DataView-or-Repeater
madhav_jain 18-Jul-16 3:01am    
I dont think there is any error in code ... do one thing change the name of Oncheckedchanged event and write new event handler in cs.
Vibhusha Devani 18-Jul-16 3:39am    
i can do this,still not working.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900