We help IT Professionals succeed at work.
Get Started

i'm creating a checkboxlist, i need to add values, not only labels, as i need to pass a different value when the ckeckbox is checked.

Erwin Pombett
on
628 Views
Last Modified: 2010-08-05
Hello experts,
my problem is as follow,
i need to fill a checkboxlist with id values and labels differents,
for example Mr.DADA has an account_id = 1111,   i need to see DADA as checkbox label,
but i need to pass the id value 1111.

HTML:
---------------------------------------------------------------------------------------------------------
                <td valign="top">
                  <asp:panel id="panAccount" runat="server">
                        <asp:Label id="lbHeaderAccount" runat="server"> </asp:Label>
                        <asp:CheckBoxList id="chklAccounts_" runat="server" ></asp:CheckBoxList>
                  </asp:panel>
            </td>

CODE BEHIND in order to populate the ckeckboxlist.
----------------------------------------------------------------------------------------------------------
...
User_ = new User(....);
DataTable dt = ApplicationConfiguration.SystemConfiguration.AccountsRepository.FetchSubAccountFromAccountID_ToDT(User_.Account_id);
                  
                  foreach(DataRow myRow in dt.Rows)
                  {
                        chklAccounts_.Items.Add(myRow["lastname"].ToString());    < --- label for the checkbox.
                                chklAccounts_.Items.  ---- myRow["id"] ----          ;                 <--- how to add a value that i will recover on postback???????
                  }


on postback, preparing an arrayList with the id values.
---------------------------------------------------------------------------------

if(IsPostBack)
{
       foreach(ListItem item in this.chklAccounts_.Items)
      {
                if(item.Selected == true)
              {
                  alAccountsToExport.Add(.....???....)   <--- how to recover the id ??????????.
            }
      }
     ........

i need to fill the lines with question mark.
thanks in advance.
Comment
Watch Question
Principal Software Engineer
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 1 Comment.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE