DataSource和DataSourceID都在'GridView1'上定义。删除一个定义。“这是什么意思 [英] Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition." What does this mean

查看:103
本文介绍了DataSource和DataSourceID都在'GridView1'上定义。删除一个定义。“这是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我用gridldatasource绑定了gridview但是无论何时执行我的程序它都显示以下错误:



两者DataSource和DataSourceID在'GridView1'上定义。删除一个定义。



现在如何解决这个错误????????

Hello friends,
I have bind the gridview with sqldatasource but whenever is execute my program it show following error:

"Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition."

Now how to solve this error????????

推荐答案

我认为您尝试使用设计方面的sqldatasource将数据绑定到数据网格,以及使用代码背后的c#代码...





我的朋友你必须这样做才能解决你的错误..



1)你需要选择一种方式绑定网格

2)如果它来自代码隐藏意味着使用c#代码然后从网格设计视图中删除网格视图中的datasourceid属性

像这样



I think you try to bind data to data grid using sqldatasource from design side as well as using c# code from code behind side..


My Friend you have to do this for solving your error..

1) You need to chose one way to bind the grid
2) if it is from code behind means using c# code then remove the datasourceid property from grid view from design view of grid
like this

<asp:gridview id="cartData" runat="server" autogeneratecolumns="False" 
DataSourceID="Datasource1">


//you have to make it like this

<asp:gridview id="cartData" runat="server" autogeneratecolumns="False">







3)如果您使用设计端绑定到网格,则必须删除c#代码以绑定网格。





因为你只需要使用一种biding方法,所以两者同时是不允许的..




3) if you use a design side binding to your grid then you have to remove the c# code to bind the grid.


Because you have to use only one method of biding, both at a same time is not permissible..


它需要你要做到这一点。您似乎在 GridView1 DataSourceID DataSource 属性C>。删除其中一个。 DataSourceID 往往在声明性标记中设置,而 DataSource 往往在代码隐藏中设置。因为您使用的是 SqlDataSource ,所以删除在代码隐藏中显式设置 DataSource 属性的所有行。
It requires you to do exactly that. You seem to have set both the DataSourceID and DataSource properties on GridView1. Remove one of them. The DataSourceID tends to be set in declarative markup and the DataSource tends to be set in codebehind. Because you're using a SqlDataSource, remove any lines that explicitly set the DataSource property in codebehind.


解决方案在这里:



Solution is Here:

public partial class _Default : System.Web.UI.Page 
{
    SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirectory|\\Database.mdf;Integrated Security=True;User Instance=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        string str = "select * from student";
        SqlDataAdapter adp = new SqlDataAdapter(str, con);
        DataSet set1 = new DataSet();
        adp.Fill(set1);
        GridView1.DataSource = set1.Tables[0];
        GridView1.DataBind();
}
}


这篇关于DataSource和DataSourceID都在'GridView1'上定义。删除一个定义。“这是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆