How to make a rapid editable gridview
This breaks every single design pattern which exists, however sometimes you want to make a rapid editable gridview without writing any code, the solution is simple, just use the designer and use EntityDataSource as your datasource. enable edit and delete buttons and you're done.
The insert auto generated button is worthless because it is NOT implemented, so you'd have to implement the insert the method yourself, no other choice (the guys at Microsoft least until framework 4 just didn't implement the insert method of the autogenerated button!)
If you'd like to sort the gridview, you can just add this piece of code:
protected void Page_PreRender(object sender, EventArgs e)
{
EntityDataSource1.OrderBy = "it.Date";
}
note the "it." prefix of the EntityDataSource1.OrderBy value - the it is the "control variable", which in this context means the gridview's variable, the gridview entitydatasource. It is followed by a column name, in the example above "Date"
that's it.
(If you'd like to take a look how to gridview looks at the aspx so it's something as simple as this:
<asp:GridView ID="GridView1" runat="server" DataSourceID="EntityDataSource1"
AutoGenerateColumns="False" DataKeyNames="RecordID" ShowFooter="true" >
<Columns>
<asp:CommandField ShowEditButton="True" ShowInsertButton="true" />
<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" dataformatstring="{0:dd-M-yyyy}" />
<asp:BoundField DataField="Begin_time" HeaderText="Begin_time"
SortExpression="Begin_time" />
</Columns>
</asp:GridView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=pcgroup1_pcgroupEntities"
DefaultContainerName="pcgroup1_pcgroupEntities" EnableDelete="True"
EnableFlattening="False" EnableInsert="True" EnableUpdate="True"
EntitySetName="WorkTimesLogs" EntityTypeFilter="WorkTimesLog" OrderBy="it.Date" >
</asp:EntityDataSource>