本文介绍了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????????
推荐答案
<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..
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'上定义。删除一个定义。“这是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!