Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Aspx
<asp:Repeater ID="rptOzellik" runat="server">
     <ItemTemplate>

      <div class="col-md-5 pad10">
         <asp:CheckBox ID="check" runat="server" />
         <asp:HiddenField ID="OzellikID" Value='<%#Eval("OzellikId") %>' runat="server" />

       </div>


     </ItemTemplate>
     </asp:Repeater>


Code Behind:
C#
int[] OzellikIdArray = new int[rptOzellik.Items.Count];
         int i = 0;
         foreach (RepeaterItem item in rptOzellik.Items)
         {
             HiddenField OzellikID = (HiddenField)item.FindControl("OzellikId");
             var checkBox = (CheckBox)item.FindControl("check");
             if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
             {

                 if (checkBox.Checked)
                 {

                     OzellikIdArray[i] = int.Parse(OzellikID.Value.ToString());
                 }

             }
             i++;
         }


I checked a few checkbox but checkBox.checked always returned false.
What i'm missing ?

What I have tried:

I tried a lot of way for solution but i couldn't solve
Posted
Updated 18-Aug-16 17:47pm

What you should do is to iterate through the controls, checking each to see if it is a checkbox.If it is, and has the right name, check the state.
 
Share this answer
 
I have tested your code, its working fine.
You will have to move the databinding code inside the !Page.IsPostBack

C#
if (!Page.IsPostBack)
            {
                rptOzellik.DataSource = yourDataSource;
                rptOzellik.DataBind();
            }
 
Share this answer
 
Comments
Kaan Öztürk 19-Aug-16 3:47am    
you are awesome my friend :)
Karthik_Mahalingam 19-Aug-16 4:43am    
welcome :)

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