Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
1.40/5 (3 votes)
See more:
i have an checkbox inside a datalist now i want dt all the item which are checked i want to find out there id
here is datalist code:
C#
<asp:DataList ID="dl1" runat="server"  <RepeatColumns="4"
      <    DataKeyField="movie_id" onitemcommand="DataList1_ItemCommand"
       <   ondeletecommand="DataList1_DeleteCommand" >
 <ItemTemplate>

    <table  cellspacing="5" >
    <tr>
    <td style="width:40%" >
    <div class="imgautoformat" style="height:150px;width:110px" >
    <img class="ader1" src='<%#"uploaded/"+ Eval("Movie_Name") %>' alt='<%# Eval("Movie_Name") %>' width="100px"
      height="140" />
     <asp:Label ID="EmpIDLabel" runat="server" Visible="false"> <%#Eval("movie_id") %></asp:Label>

      </div>
        </td>
        <td style="width:60%;text-align:center" >

            <asp:CheckBox ID="chked_item" runat="server" Text=" select for shop" />
        <asp:Label ID="Label" runat="server" Text='<%# Eval("label") %>' />
        <br />
      <b style="color:Red" >  &#36
        <asp:Label ID="priceLabel" runat="server" Text='<%# Eval("price") %>'/></b>
        <br />
          <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" CommandArgument='<%#Eval("movie_id") %>'
            Text="Delete" OnClientClick="return confirm('Are You Sure to Delete?')" />
        </td>
</tr>
</table>
    </ItemTemplate>
 </asp:DataList>

and below is page behind code:
C#
protected void cartadd_Click(object sender, EventArgs e)
        {
            foreach (DataListItem li in dl1.Items)
            {
                CheckBox chked_item = (CheckBox)li.FindControl("chked_item");
                if (chked_item != null)
                {
                    if (chked_item.Checked==true)
                    { 
                        
                    }
                }
            }
        }

now how to find id of selected item i want to insert dt items in to database??
Posted
Updated 11-Dec-17 20:32pm
v2

protected void cartadd_Click(object sender, EventArgs e)
        {
            Cart_table objta = new Cart_table();
            string om = 0.ToString();
           
            foreach (DataListItem li in dl1.Items)
            {
                CheckBox chked_item = (CheckBox)li.FindControl("chked_item");
                if (chked_item != null)
                {
                    if (chked_item.Checked==true)
                    {
                        int  x  = Convert.ToInt32(((Label)li.FindControl("Label1")).Text);
                        var movie = (from st in obj.Cart_tables
                                    where st.username==Session["user"].ToString() && st.movie_id==x
                                     select st.movie_id).SingleOrDefault();
                        if (x !=Convert.ToInt32(movie))
                        {
                            objta.movie_id = x;
                            objta.username = Session["user"].ToString();
                            obj.Cart_tables.InsertOnSubmit(objta);
                            obj.SubmitChanges();
                        }
                    }
                }
            }
        }
 
Share this answer
 
function chkValue(chk) {
////check if user have checked or unchecked the checkbox
if (chk.checked == true) {
//if checked add ID in hidden variable
//saving all ID's in hidden variable
debugger;
$('#hdnBranchID').val($('#hdnBranchID').val() + ',' + chk.innerHTML);
document.getElementById('btnSend').disable = false;

}
else {
//If uncheked then Remove same ID from Hidden variable
$('#hdnBranchID').val($('#hdnBranchID').val().replace(chk.innerHTML, ''));
$('#hdnBranchID').val($('#hdnBranchID').val().replace(',,', ','));

}
}
 
Share this answer
 
Comments
Deepu S Nair 12-Dec-17 2:37am    
You are answering a question which is nearly 5 years old and already solved .It may attract downvoting your answer.Please try to answer new questions

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