Adding controls to footer of DataList at runtime problem

bri189a

Senior Contributor
Joined
Sep 11, 2003
Messages
1,004
Location
VA
The page I'm working on contains a datalist, but I'm making it have the ability to page. I find it stupid that the only control that M$ made with paging built it was the DataGrid as most people don't want their site to look like a spread sheet. But I digress, here is the code that I'm adding when the footer is being created:

C#:
[size=2][color=#0000ff]if[/color][/size][size=2](e.Item.ItemType==ListItemType.Footer && [/size][size=2][color=#0000ff]this[/color][/size][size=2].PageCount!=0)[/size]
[size=2]{[/size]
[size=2]   LinkButton [] Pages = [/size][size=2][color=#0000ff]new[/color][/size][size=2] LinkButton[[/size][size=2][color=#0000ff]this[/color][/size][size=2].PageCount];[/size]
    [size=2][color=#0000ff]for[/color][/size][size=2]([/size][size=2][color=#0000ff]int[/color][/size][size=2] i=0;i<Pages.Length;i++)[/size]
[size=2]    {[/size]
[size=2]        Pages[i] = [/size][size=2][color=#0000ff]new[/color][/size][size=2] LinkButton();[/size]
[size=2]        Pages[i].ID = "lnkBtnPage" + i.ToString();[/size]
[size=2]        Pages[i].Text = (([/size][size=2][color=#0000ff]int[/color][/size][size=2])(i + 1)).ToString();[/size]
[size=2]        Pages[i].CommandName = "Pages";[/size]
[size=2]        Pages[i].CommandArgument = Pages[i].Text;[/size]
[size=2]   }[/size]
[size=2]}
[/size]

The LinkButtons get added perfectly, the problem is that nothing happens on the DataList_ItemCommandEvent as it should. I've tried attaching an event, which shouldn't work because it a piece of the DataList and it didn't, as I suspected. I put a link button there manually in design view and it works fine, so the problem I think is that the view state isn't being passed back to the server. How do I resolve this problem... I'm lost at this point; the fact that I got this far is pretty good considering my experience with ASP.NET

Thanks in advance!
 
Back
Top