• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1649
  • Last Modified:

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


0
mugsey
Asked:
mugsey
  • 2
  • 2
1 Solution
 
Anurag ThakurTechnical ManagerCommented:
--->>> //NEED TO GET THE DATAKEY VALUE FOR THE TEXTBOX
what text box you are talking about
0
 
mugseyAuthor Commented:
Whoops sorry I mean checkbox!!!!
0
 
Anurag ThakurTechnical ManagerCommented:
i still dont completely understand your question
i will rephrase and let me know if i am correct or wrong
you want to get the DataKey ID for the row you have selected in the listview so that the underlying data can be updated accordingly
if yes then have a look at the following link sample http://forums.asp.net/p/1294023/2507309.aspx
Ragi
0
 
mugseyAuthor Commented:
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)
            {
               
            }

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now