This Damn Thing Should Work

Tuesday, May 31, 2005

Itemcommand and the Repeater

As part of our content management system, I decided to incorporate a way to expand/collapse portions of the heirarchical list of pages, kinda like a treeview. Great idea - but man a pain in the ass.

Part of the issue was that the way I wanted to handle it was to have each row in the datalist have an idea and be able to be turned on and off with Javascript (so no refresh when expanding/collapsing). Well, to the best of my research I couldn't find a way to attach ids to rows in a datagrid or a datalist. You could make individual tables in a datalist, but without being able to control the rows themselves you get extra space between the collapsed items (empty rows). So I had to go with the repeater.

But the repeater has no built in datakeyfield stuff (which I think is a stupid thing in the first place - the repeater is the only one of the three that give you complete flexibility in presentation). So I have to fake it - here's how I did it -

I put a hidden field as part of the ItemTemplate on the repeater - runat="server", an id of "idval" and the value attribute set to the page_id of the record.

Then on the ItemCommand I've got:

If e.CommandName = "edit" then
Call EditForm(cType(e.item.FindControl("idval"),HtmlInputHidden).Value)
Else
'other stuff
End If

So basically it checks the container of the button I pressed and searches for the idval and grabs it to use in the edit/delete subs. It's not pretty (at least to me) but it works. I like the flexibility of the repeater - I'm guessing I'll be using this again.

So the expansion/collapsing works for the most part - some minor mozilla issues with the javascript still exist but its getting there. The client code to make the whole thing work was another pain in the ass...

0 Comments:

Post a Comment

<< Home