Solved

Dynamically add checkboxes in gridview

Posted on 2010-11-22
4
771 Views
Last Modified: 2012-05-10
Hi,
i have a gridview which lists the project and shows for each project whether member of the specified group are stafed or not. I thus have 1 column for the project and would like to dynamically add one column per group member.
What I want to do is:
1 create the columns on page_load
2 bound the data for each colum on rowdatabound event

1 is working find and I create columns with user.initials as headertext
I'm not able to retrieve the checkbox on 2 and to bound the data

thks for your help
 
1. page_load

                Dim select_user_list = "select id_user, initials from [user] where id_group = " + ADTools.GetGroupID(ADTools.GetADUserGroups(My.User.Name, "time_")).ToString
                Dim ds_users = DataTools.DataSql(select_user_list)
                For Each objRow As DataRow In ds_users.Tables(0).Rows
                    Dim chkf_staf As New CheckBoxField
                    Dim user_initials = objRow("initials").ToString
                    chkf_staf.HeaderText = user_initials
                    chkf_staf.Text = False
                    gvStaff.Columns.Add(chkf_staf)

2. rowdatabound

            Dim chk_staf As CheckBox = CType(gvStaff.FindControl(user_initials), CheckBox)
            chk_staf.Checked = True

Open in new window

0
Comment
Question by:jeebee75
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 20

Expert Comment

by:informaniac
ID: 34193681
Try this..

Dim chk_staf As CheckBox = CType(gvStaff.FindControl(chkf_staf), CheckBox)
0
 

Author Comment

by:jeebee75
ID: 34193999
hi,

i've tried that but it doesn't work. I finally found a partial solution to my problem in rowdatabound (my dynamic checkbox columns start at index 4):

            For i = 4 To gvStaff.Columns.Count - 1
                Dim chkBox = New CheckBox
                chkBox.Enabled = True
                e.Row.Cells(i).Controls.Add(chkBox)
                Dim user_initials = gvStaff.Columns.Item(i).ToString
                Dim test_staf = "select count(*) from staffing inner join [user] on staffing.id_user = [user].id_user where id_comp_proj = " + id_cp + " and [user].initials = '" + user_initials + "'"
                If DataTools.ExecScSql(test_staf) = 0 Then
                    chkBox.Checked = False
                Else : chkBox.Checked = True
                End If
            Next

This create checkbox and bind the correct value in it.
Now I want to catch the event when user change one of the checkboxes and make the relevant update in the database.
If you have any idea... I was thinking using rowcommand but I don't know how to retrieve the information from the chekkbox that has been modified (column index??).

Regards,

JBS
0
 
LVL 29

Accepted Solution

by:
Kumaraswamy R earned 500 total points
ID: 34194059
0
 

Author Closing Comment

by:jeebee75
ID: 34201921
works
0

Featured Post

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

635 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question