[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1634
  • 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 ThakurCommented:
--->>> //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 ThakurCommented:
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

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

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