面对错误都DataSource和与DataSourceID的是在GridView的实体框架定义 [英] Facing error both DataSource and And DataSourceID are defined on GridView Entity Framework
问题描述
我使用实体框架的工作,并要绑定的网格视图的数据,但面临的问题,我有code是我和粘贴以及附加的屏幕快照我也看到了回答关于这个问题,但不利于我,所以任何人不得不与此错误的经验一定是AP preciated。
aspx.cs code
保护无效的Page_Load(对象发件人,EventArgs的发送)
{
如果(!的IsPostBack)
{
BindGrid();
}
lblMessage.Text =;
} 无效BindGrid()
{
使用(GapEntities1上下文=新GapEntities1())
{
如果(context.Organizations.Count()大于0)
{
// GdvOrganization是一个gridview ID名称
GdvOrganization.DataSource = context.Organizations;
GdvOrganization.DataBind();
}
}
}
好像你正试图在GridView从标记侧(的.aspx)以及使用code背后绑定。(.aspx.cs)
选择任何一种方式只对电网进行绑定。
1)。如果你从code绑定gridview的背后然后取出从标记网格视图的DataSourceID
属性。低于code改变:
< ASP:GridView控件ID =GdvOrganization=服务器的AutoGenerateColumns =FALSE
的DataSourceID =MyDataSource>
到
< ASP:GridView控件ID =GdvOrganization=服务器的AutoGenerateColumns =FALSE>
2)。如果你preFER从侧面标记绑定,那么你必须删除C#code到网格绑定。
不过,如果上述两个步骤你不感兴趣,试试下面的技巧(推荐?)
GdvOrganization.DataSource = DS;
GdvOrganization.DataSourceID =的String.Empty;
GdvOrganization.DataBind();
i am using entity frame work and want to bind data on Grid View but facing problem i have code that i am pasting as well as attaching screen shot i also saw answer regarding this problem but not beneficial for me so any one have experience with this error must be appreciated.
aspx.cs Code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
lblMessage.Text = "";
}
void BindGrid()
{
using (GapEntities1 context = new GapEntities1())
{
if (context.Organizations.Count() > 0)
{
// GdvOrganization is a gridview ID name
GdvOrganization.DataSource = context.Organizations;
GdvOrganization.DataBind();
}
}
}
Seems like you are trying to bind the GridView from Markup side (.aspx ) as well as using code behind.( .aspx.cs )
Choose any one way only to bind the grid.
1.) If you bind gridview from code behind then remove the DataSourceId
property from grid view from markup. Change below code:
<asp:gridview id="GdvOrganization" runat="server" autogeneratecolumns="False"
DataSourceID="MyDataSource">
to
<asp:gridview id="GdvOrganization" runat="server" autogeneratecolumns="False">
2.) if you prefer to bind from markup side then you have to remove the c# code to bind the grid.
Still if above 2 steps doesn't interest you, try below trick ( Recommended ?? )
GdvOrganization.DataSource = ds;
GdvOrganization.DataSourceID = String.Empty;
GdvOrganization.DataBind();
这篇关于面对错误都DataSource和与DataSourceID的是在GridView的实体框架定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!