Hello all, I got suddenly a new error, I found for it at google but solutions seems entire different approach.
My code is below.
Code:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="false"
AllowSorting="True" DataSourceID="EntityDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ItemStyle-Width="100px" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" ItemStyle-Width="200px" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" ItemStyle-Width="300px" />
<asp:TemplateField HeaderText="User Name">
<ItemTemplate>
<asp:Label ID="lblUsers" runat="server" Text='<%# GetUserName(Eval("UserId")) %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="ddlUsers" runat="server" DataSourceID="SqlDataSource1" DataTextField="UserName" DataValueField="UserId"
SelectedValue='<%# Bind("UserId") %>'>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:EntityDataSource ID="EntityDataSource1" runat="server"
ConnectionString="name=ASPNETDBEntities"
DefaultContainerName="ASPNETDBEntities" EnableDelete="True"
EnableFlattening="False" EnableInsert="True" EnableUpdate="True"
EntitySetName="Plots">
</asp:EntityDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT UserId,UserName FROM [aspnet_Users]"></asp:SqlDataSource>
and code behind is
Code:
protected string GetUserName(object userid)
{
string userName = (string)Membership.GetUser(userid).UserName;
return userName;
}
But I am getting error "Store update, insert, or delete statement affected an unexpected number of rows (0). Entities may have been modified or deleted since entities were loaded. Refresh ObjectStateManager entries."
I am getting this error on Edit and Delete operation only, if I add a DetailsView to insert record then it works fine. Also if I don;t use AutoGenerateColumns=False, then also it works.
Please tell me what is issue and how I resolve it???