webForumDet fria alternativet

Paging fel säger att ICollection behövs?

.NET

2 svar · 247 visningar · startad av CokeLight

Medlem sedan juni 2000504 inlägg
Frågan#1

Hej,

Satte just in AllowPaging i DataGrid.. fick då msg:

AllowCustomPaging must be true and VirtualItemCount must be set for a DataGrid with ID dgData when AllowPaging is set to true and the selected datasource does not implement ICollection.

efter att ha bytt till AllowCustomPaging får jag detta istället:

Cannot compute Count for a data source that does not implement ICollection.

kollar lite i dokumentationen men hänger dessvärre inte med hur jag ska implementera ICollection för att pagingen ska fungera...? Nån som har tips...?

Medlem sedan dec. 2000399 inlägg
#2

Hur ser koden ut runt omkring? Vilken typ av datakälla använder du?

Medlem sedan juni 2000504 inlägg
#3

Kan kanske tillägga att paging fungerade bra när jag bara listade normalt från databas, men att ovanstående problem uppstod när en lista med editerings (OnEditCommand) möjligheter loopades fram i kombination med paging.

Men jag hittade lite info till slut:

Also note that to utilize the default paging with a DataGrid Web control you must use a DataSet. That is, if you set AllowPaging to True but do not employ custom paging, you cannot bind a SqlDataReader or OleDbDataReader to the DataGrid Web control and implement paging. If you attempt to do so you will receive an error along the lines of: "To support paging, you must use an object that supports the ICollection interface."

This error message occurs because the DataReader objects do not support the ICollection interface. Note that the DataSet does not support this intercace directly either; however, the DataSet does support the IListSource interface, which is inherited from the IList interface, which is inherited from the ICollection interface. Hence, the DataSet can be used to implement paging with the DataGrid Web control.

Jag kom på att jag gjorde fel förut.. man ska tydligen ha både
AllowPaging
AllowCustomPaging

samtidigt, vilket jag inte kom på först. Nu har jag lite annorlunda problem.. Paging visar bara 1 och jag kan inte klicka på den.. kör man PrevNext så blir dessa inte hyperlänkar heller..? Det som är konstigt är att även fast PageSize="10" så visas 12 rader.. ??bleh.. :)

Kod för DataGrid just nu...

<asp:DataGrid id="dgData" runat="server" 
      	AutoGenerateColumns="False"
      	AllowPaging="True"
	AllowCustomPaging="True"
	PageSize="10"
	PagerStyle-Mode="NumericPages"
	PagerStyle-HorizontalAlign="Right"
	OnPageIndexChanged="dgData_PageIndexChanged"
	BorderColor="black"
	BorderWidth="1"
	GridLines="Both"
	CellPadding="3"
	CellSpacing="0"
	Font-Name="Verdana"
	Font-Size="8pt"
	HeaderStyle-BackColor="#aaaadd"
	AlternatingItemStyle-BackColor="#eeeeee"
	OnDeleteCommand="dgData_Delete"
 	OnEditCommand="dgData_Edit"
	OnCancelCommand="dgData_Cancel"
        OnUpdateCommand="dgData_Update">
		 
         <Columns>
              ...
         </Columns>
      </asp:DataGrid>

Vet inte om felet ligger här eller nån annanstans.. provade koppla ett DataSet som implementerade ICollection till min DataGrid men jag måste antingen gjort fel för inget hände, eller så var det irrelevant för problemet.. ?

256 ms totalt · 4 externa anrop · v20260731065814-full.6fe65c25
125 ms — deklarationer (db)
0 ms — hämta statistik (cache)
128 ms — hämta tråd, inlägg och bilagor (db)
120 ms — ändringar (db)