Link to home
Start Free TrialLog in
Avatar of mugsey
mugseyFlag for United Kingdom of Great Britain and Northern Ireland

asked on

get datakey item from checkbox in listview control

I populate listview with checkbox that is populated from database like this........

<asp:ListView ID="List" runat="server" DataKeyNames="Id">
                        <LayoutTemplate>
                            <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder>
                        </LayoutTemplate>
                        <ItemTemplate>
                                <asp:CheckBox ID="ListCheckBoxField" runat="server" Text='<%#Eval("Description") %>' />
                        </ItemTemplate>                                              
                    </asp:ListView>


.......
      for (int i = 0; i < List.Items.Count; i++)
        {
            var item = List.Items[i];
            var checkbox = item.FindControl("checkboxControl") as CheckBox;

            if (checkbox != null && checkbox.Checked)
            {
                //NEED TO GET THE DATAKEY VALUE FOR THE TEXTBOX
            }
        }  

...

I need to get each datakey value of the checkbox


Avatar of Anurag Thakur
Anurag Thakur
Flag of India image

--->>> //NEED TO GET THE DATAKEY VALUE FOR THE TEXTBOX
what text box you are talking about
Avatar of mugsey

ASKER

Whoops sorry I mean checkbox!!!!
ASKER CERTIFIED SOLUTION
Avatar of Anurag Thakur
Anurag Thakur
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mugsey

ASKER

Thanks but it is not updating is it inserting into table

So the listview control containing one checkbox is populated from database.   The database table has ID, Description so this is how checkboxes are populated.

If a checkbox is checked I want to get the underlying Primary Key of the checkbox as it is populated from the database.  



            var item = List.Items[i];
            var checkbox = item.FindControl("checkboxControl") as CheckBox;

            if (checkbox != null && checkbox.Checked)
            {
               
            }