Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Dynamically add checkboxes in gridview

Posted on 2010-11-22
4
Medium Priority
?
772 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 1500 total points
ID: 34194059
0
 

Author Closing Comment

by:jeebee75
ID: 34201921
works
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

705 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