“Both DataSource and DataSourceID are defined” error using ASP.NET GridView

后端 未结 7 2300
面向向阳花
面向向阳花 2021-02-15 06:38

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

I just got this error today, the code has been working until this after

7条回答
  •  名媛妹妹
    2021-02-15 07:02

    tslib is right, don't do: grdCommunication.DataSourceID = null; or the string.Empty version. You only use the DataSourceID if you're using a SqlDataSource or ObjectDataSource control for your binding.

    It's called "declarative" binding because you're using "declared" controls from on your page. Binding to controls does not require a call to the DataBind() method.

    Because you're DataBinding manually (calling grd.DataBind()) you only set the DataSourrce and then call DataBind().

提交回复
热议问题