hello
when i update the data in the gridview an error occur in entity framework 6.0?
A public method with the name 'Gv2_GetData' was either not found or there were multiple methods with the same name on the type 'ASP.webform63_aspx'.
here is my code how to solve
cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Entity.Infrastructure;
namespace WebApplication14
{
public partial class WebForm63 : System.Web.UI.Page
{
// mann mode = new mann();
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
Clear();
}
void Clear()
{
tb_benefited.Text = tb_allowance.Text = "";
Button1.Text = "save";
}
protected void Button1_Click(object sender, EventArgs e)
{
//mode.benefited_leaves1 = tb_benefited.Text.Trim();
//mode.basic_allowance1 = tb_allowance.Text.Trim();
using (hospitalEntities ctx = new hospitalEntities())
{
// db1.manns.Add(mode);
// db1.SaveChanges();
ctx.manns.Add(new mann()
{
benefited_leaves1 = tb_benefited.Text,
basic_allowance1 = tb_allowance.Text
});
ctx.SaveChanges();
Clear();
}
}
// The return type can be changed to IEnumerable, however to support
// paging and sorting, the following parameters must be added:
// int maximumRows
// int startRowIndex
// out int totalRowCount
// string sortByExpression
//public IQueryable<WebApplication14.hospitalEntities.Models.mann> Gv2_GetData()
//{
// return null;
//}
// The id parameter name should match the DataKeyNames value set on the control
public void Gv2_UpdateItem(int tbl_id)
{
using (hospitalEntities db = new hospitalEntities())
{
mann item = null;
item = db.manns.Find(tbl_id);
if (item == null)
{
// The item wasn't found
ModelState.AddModelError("", String.Format("Item with id {0} was not found", tbl_id));
return;
}
TryUpdateModel(item);
if (ModelState.IsValid)
{
db.SaveChanges();
}
}
}
}
}
aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm63.aspx.cs" Inherits="WebApplication14.WebForm63" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="tb_benefited" runat="server" ></asp:TextBox>
<asp:TextBox ID="tb_allowance" runat="server" ></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:GridView runat="server" ID="Gv2" ItemType="WebApplication14.hospitalEntities.Models.mann" DataKeyNames="tbl_id" SelectMethod="Gv2_GetData" UpdateMethod="Gv2_UpdateItem"
AutoGenerateEditButton="true" CellPadding="4" ForeColor="#333333" GridLines="both" AutoGenerateColumns="false" Width="90%" AllowPaging="true" PageSize="10">
<AlternatingRowStyle BackColor="White" />
<Columns>
<%-- <asp:BoundField DataField="benefited_leaves1" HeaderText="Benefited Leaves" />
<asp:BoundField DataField="basic_allowance1" HeaderText="Basic Allowance" />--%>
</Columns>
<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" />
</asp:GridView>
</form>
</body>
</html>