这两个DataSource和DataSourceID的是在“GridView1”定义。删除一个定义 [英] Both DataSource and DataSourceID are defined on 'GridView1'. Remove one definition

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

问题描述

我使用一个GridView和SqlDataSource控件的数据表信息到GridView绑定。
在GridView控件更新事件我有以下的code:

I'm using a gridview and SqlDataSource to bind the data table information to the gridview. On gridview update event I have the following code :

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
  {
                    var ID = (int)GridView1.DataKeys[e.RowIndex]["No"];
                    string costring = "the conn string";
                    string query = "UPDATE mytable SET Age = @Age WHERE No = " + ID;
                    using (SqlConnection dataConnection = new SqlConnection(costring))
                    {
                        using (SqlCommand com = new SqlCommand(query, dataConnection))
                        {
                            dataConnection.Open();
                            int valueID = 18;
                            com.Parameters.AddWithValue("Age", valueID);
                            com.ExecuteNonQuery();
                            GridView1.DataSource = SqlDataSource1;
                            GridView1.DataBind();
                            dataConnection.Close();
                        }
                    }
                 }


  • 如果我点击更新事件我得到:无论DataSource和DataSourceID的
    上'GridView1'被定义。删除一个定义。在这里
    GridView1.DataBind();!但是当我刷新网页中的code
    的工作,但我总是得到这个错误。

  • 我搜索谷歌和我发现,我无法使用both..but我需要
    看到GridView控件的信息,我无法删除
    SqlDataSource的结合,也是我需要使code的工作。

  • 我试过DataGridviewID = NULL;我没有得到任何错误,但
    没有什么改变code未发生executed..nothing

  • 推荐答案

    你真的需要重新分配数据源,如果你发出这个声明

    Do you really need to assign data source again if you emit this statement

      GridView1.DataSource = SqlDataSource1;
      GridView1.DataBind();
    

    和使用

      SqlDataSource1.Update();
    

    有是一个使用数据源的一个例子,我希望这将有助于你的数据源的例子

    There is an example of using datasource, i hope that will help you Datasource example

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

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