Click to See Complete Forum and Search --> : [RESOLVED] Dynamic Controls vs Repeater


Scott.Macmaster
June 26th, 2008, 11:30 AM
I initially built a page using dynamic controls. Now, I have to add some more functionality into it and I'm having difficulty getting the page to work.

My page list items and there properties. The first 2 columns are there name and id. There are about 30 properties. So I have a drop down to select certain groups of properties. I also have 4 checkboxes to show properties that don't fit into the other groupings. Each row has an edit button that turns the text for the properties into text boxes.

That all is working fine. However, now I'm changing one of the properties. Previously, it wasn't editable because it was a calculated value. Now, when the user clicks edit, I want a button to appear that says 'override'. Clicking this then allows the property to be editable. Then problem I'm having is I can't get the click event of the override button to wire up with the event handler function.

I'm looking into using a repeater control and hoping it'll make this all simpler. I started to code this repeater control and quickly came across a problem. I can find no way to have a variable number of columns. Maybe I can have 16 repeater controls. There are 4 items in the drop down and 4 check boxes so there are 16 possible combinations. However, switching between the repeater controls would end up turning off edit on rows. This is fine for changing the item in the dropdown but not for changing the checkboxes.

So it would be great if someone could suggest a way to vary the number of columns in a repeater control or maybe suggest another approach to this.


Thanks,
Scott

Scott.Macmaster
June 26th, 2008, 01:45 PM
Oh, I figured out a workable solution. Setup the repeater to include all possible columns. Then use the ItemCreated event to remove columns I don't want to show.

Still a lot more to do but here's what I've got in case anyone wants to see how I did this.


Protected Sub Repeater1_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles Repeater1.ItemCreated

Dim row As HtmlTableRow = CType(e.Item.FindControl("rowMyRow"), HtmlTableRow)

If e.Item.ItemType = ListItemType.Header Or e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

If lstLeaveType.SelectedValue = "S" Then
row.Cells.RemoveAt(6)
row.Cells.RemoveAt(5)
row.Cells.RemoveAt(4)
ElseIf lstLeaveType.SelectedValue = "V" Then
row.Cells.RemoveAt(6)
row.Cells.RemoveAt(5)
row.Cells.RemoveAt(3)
ElseIf lstLeaveType.SelectedValue = "P" Then
row.Cells.RemoveAt(6)
row.Cells.RemoveAt(4)
row.Cells.RemoveAt(2)
ElseIf lstLeaveType.SelectedValue = "E" Then
row.Cells.RemoveAt(5)
row.Cells.RemoveAt(4)
row.Cells.RemoveAt(2)
End If

End If

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

Dim employee As EmployeeReport.Employee = CType(e.Item.DataItem, Global.System.Collections.Generic.KeyValuePair(Of String, Global.PersonnelSystem_HR_ManageEarnedLeave.EmployeeReport.Employee)).Value

If employee Is Nothing = False Then
row.Cells(0).InnerText = employee.Name.ToString()
End If

End If

If e.Item.ItemType = ListItemType.Footer Then
row.Cells(0).ColSpan = 5
End If

End Sub