Nesting gridview/formview in webuser control inside a parent gridview

Posted by Stuart on Stack Overflow See other posts from Stack Overflow or by Stuart
Published on 2009-12-09T10:35:57Z Indexed on 2010/04/06 7:03 UTC
Read the original article Hit count: 671

Filed under:
|

Hi,

I'm developing an ASP.net 2 website for our HR department, where the front page has a matrix of all our departments against pay grades, with links in each cell to all the jobs for that department for that grade. These links take you a page with a gridview populated dynamically, as each department has a different number of teams, e.g. Finance has one team, IT has four. Each cell has a webuser control inserted into it. The user control has a sql datasource, pulling out all the job titles and the primary key, popuating a formview, with a linkbutton whose text value is bound to the job title. (I'm using a usercontrol as this page will also be used to show the results of a search of all roles in a range of grades for a department, and will have a varying number of rows).

I've got everything to display nicely, but when I click on the linkbutton, instead of running the code I've put in the Click event, the page posts back without firing any events.

Having looked around, it looks like I have to put an addhandler line in somewhere, but I'm not sure where, could anyone give me some pointers please? (fairly numpty please, I'm not too experience in ASP yet and am winging it. I'm also using VB but C# isn't a problem)

This is how I'm inserting the controls into the parent grid, have I missed anything obvious?

        For row As Int16 = 0 To dgvRoleGrid.Rows.Count - 1
            tempwuc = New UserControl
            tempwuc = LoadControl("wucRoleList.ascx")
            tempwuc.ID = "wucRoleList" & col.ToString
            tempwuc.EnableViewState = True
            dgvRoleGrid.Rows(row).Cells(col).Controls.Add(tempwuc)
            CType(dgvRoleGrid.Rows(row).FindControl(tempwuc.ID), wucRoleList).specialtyid = specid
            CType(dgvRoleGrid.Rows(row).FindControl(tempwuc.ID), wucRoleList).bandid = dgvRoleGrid.DataKeys(row)(0)
            CType(dgvRoleGrid.Rows(row).FindControl(tempwuc.ID), wucRoleList).familyid = Session("familyid")


        Next

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about gridview