데이터 소스로 objectdatasource가있는 GridView에서 정렬 할 수 있도록 자습서를 진행 중입니다. http://www.devtoolshed.com/content/gridview-objectdatasource-linq-paging-and-sortingGridView를 ObjectDataSource로 정렬 오류 메시지
그것은 꽤 곧장 앞으로 보인다, 그러나 나는이 코드를 실행하면,
public List<tbl_Batch> SelectAllList(string sSortType, int iBeginRowIndex, int iMaximumRows)
{
using (TestEntities dbContext = new TestEntities())
{
var query = from q in dbContext.tbl_Batch
select q; // sort
query = SelectAllSort(query, sSortType); // filter the list if needed
query = SelectAllQuery(query); // paginate
query = query.Skip(iBeginRowIndex).Take(iMaximumRows); // execute the query and convert to list
return query.ToList();
}
}
는 마지막 줄 반환 query.ToList에 도달
(); 오류 메시지가 표시됩니다. 음수가 아닌 값이 있어야합니다. 매개 변수 이름 : limit 이 오류의 원인을 알 수 없으며 어디에서나이 정보를 찾을 수 없습니다.내 GridView에 대한 코드는 누구나 내가 잘못하고있는 것을 말해 줄 수 있습니까?
<asp:GridView ID="GridView1" runat="server" DataKeyNames="intBatchID"
AllowPaging="True" OnDataBound="GridView1_DataBound" OnRowDataBound="GridView1_RowDataBound"
AllowSorting="True" AutoGenerateColumns="False" SkinID="NOCTS" EnableSortingAndPagingCallbacks="True"
BorderStyle="Solid" HeaderStyle-BackColor="#990033" Width="1000px"
DataSourceID="ObjectDataSource1" OnSorting="GridView1_Sorting">
<HeaderStyle ForeColor="White"></HeaderStyle>
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="intBatchID" HeaderText="Batch ID" DataNavigateUrlFormatString="TestPage1.aspx?intBatchID={0}" DataTextField="intBatchID" />
<asp:BoundField DataField="vcharName" HeaderText="Name" ReadOnly="True"
SortExpression="vcharName" />
<asp:BoundField DataField="dtmScheduled" HeaderText="Date Scheduled"
ReadOnly="True" SortExpression="dtmScheduled" />
<asp:BoundField DataField="intBatchPriorityLevel"
HeaderText="Priority Level" ReadOnly="True"
SortExpression="intBatchPriorityLevel" />
</Columns>
<PagerSettings Mode="NumericFirstLast" Position="TopAndBottom" PageButtonCount="4" PreviousPageText="Previous" NextPageText="Next" FirstPageText="First" LastPageText="Last" />
<PagerStyle HorizontalAlign="Center" />
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
SelectMethod="SelectAllList" TypeName="NOCTSWebApplication.App_Code.Class3"
OnSelected="ObjectDataSource1_Selected" EnablePaging="True"
MaximumRowsParameterName="iMaximumRows" OldValuesParameterFormatString="original_{0}"
StartRowIndexParameterName="iBeginRowIndex" SortParameterName="sSortType">
<SelectParameters>
<asp:Parameter Name="sSortType" Type="String" />
<asp:Parameter Name="iBeginRowIndex" Type="Int32" />
<asp:Parameter Name="iMaximumRows" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
더 이상 내 코드가 필요하면 알려주십시오. 당신의 셋업에서 누락 적어도 일부 요소가 있습니다
private IQueryable<tbl_Batch> SelectAllQuery(IQueryable<tbl_Batch> query)
{
return query;
}
private IQueryable<tbl_Batch> SelectAllSort(IQueryable<tbl_Batch> query, string sSortType)
{
using (TestEntities dbContext = new TestEntities())
{
bool bIsSortDescending = false;
if (!String.IsNullOrEmpty(sSortType))
{
string[] sValues = sSortType.Split(' ');
if (sValues.Length > 1)
{
if (sValues[1].ToUpper() == "DESC")
{
bIsSortDescending = true;
}
}
}
if (!String.IsNullOrEmpty(sSortType))
{
query = dbContext.tbl_Batch.OrderBy(sSortType);
}
else
{ // use a default sort here
if (bIsSortDescending)
{
query = query.OrderByDescending(q => q.intBatchID);
}
else
{
query = query.OrderBy(q => q.vcharName);
}
}
return query;
}
}
public int SelectCount()
{
using (TestEntities dbContext = new TestEntities())
{
var query = from q in dbContext.tbl_Batch
select q;
query = SelectAllQuery(query); // execute the query and return the count
return query.Count();
}
}
'SelectAllQuery' - 무엇 이죠? 또한 페이징 한계 (iMaximumRows) 값을 확인하십시오. –
@WiktorZychla iMaxiumumRows의 값은 -1입니다. SelectAllQuery를 볼 수 있도록 나머지 코드를 추가했습니다. 당신의 도움을 주셔서 감사합니다. – hollyquinn
결과 집합에서 -1 행을 가져올 수 없습니다. 이것이 예외를받는 이유입니다. –