PDA

View Full Version : سوال: خطا در زمان صفخه بندی گرید



z_software
دوشنبه 22 اردیبهشت 1393, 23:40 عصر
سلام دوستان ، خسته نباشید.
راستش من گریدم رو با استفاده از entity framwork به بانکم وصل کردم.خدا رو شکر مشکلی نداره و کار میکنه ، فقط زمانی که رویدادallowpaging گرید رو true کردم و گرید رو صفحه بندی کردم، موقع اجرا خطای
For the EntityDataSource, if the query specifies a projection and paging is enabled, a sort expression must be defined. Either set the OrderBy property or set AutoGenerateOrderByClause to true.رو بهم میده !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!1
دوستان کسی میتونه کمکم کنه ؟؟؟؟؟؟؟؟؟
مرسی .

meisam12
سه شنبه 23 اردیبهشت 1393, 00:08 صبح
در رویداد PageIndexChanging گریدت کد زیر را بنویس:

protected void grdFactor_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
grdFactor.PageIndex = e.NewPageIndex;
grdFactor.DataSource=//Sellect All
grdFactor.DataBind();

}

z_software
سه شنبه 23 اردیبهشت 1393, 00:55 صبح
مرسی دوست عزیز، ولی من با کوئری گریدم رو به بانک وصل نکردم ، با استفاده از روش مستقیم اتصال به بانک و از طریق entity گردید رو به بانک وصل کردم.
میدونم یه کم بد توضیح دادم. این کد سمت design هستش :

<asp:GridView ID="GridBest" runat="server" CellPadding="4"
DataSourceID="EntityDataSource1" ForeColor="#333333" GridLines="None"
AutoGenerateColumns="False"
DataKeyNames="SourenaBestID"
onselectedindexchanged="GridBest_SelectedIndexChanged" AllowPaging="True"
onpageindexchanging="GridBest_PageIndexChanging" PageSize="3"
AllowSorting="True">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
<Columns>
<asp:TemplateField HeaderText="انتخاب">
<ItemTemplate>
<asp:CheckBox ID="SelectChckBox" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ویرایش">
<ItemTemplate>
<asp:ImageButton ID="EditButton" runat="server" ImageUrl="~/Images/Edit.png"
CommandName="Select" onclick="EditButton_Click"
/>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="BestLabel" runat="server" Text='<%#Eval("SourenaBestID")%>'></asp:Label>
</ItemTemplate>
<ControlStyle BorderWidth="0px" Width="0px" />
<FooterStyle BorderWidth="0px" Width="0px" />
<HeaderStyle BorderWidth="0px" Width="0px" />
<ItemStyle Width="0px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="نام و نام خانوادگی">
<ItemTemplate>
<%#Eval("FullName")%>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="تاریخ درج ">
<ItemTemplate>
<%#Eval("InsertDate")%>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=SourenaDatabaseEntities"
DefaultContainerName="SourenaDatabaseEntities" EnableFlattening="False"
EntitySetName="SourenaBest"
Select="it.[SourenaBestID], it.[FullName], it.[InsertDate]
">
</asp:EntityDataSource>