gpt4 book ai didi

c# - 将数据源动态绑定(bind)到 gridview

转载 作者:太空宇宙 更新时间:2023-11-03 13:39:33 25 4
gpt4 key购买 nike

我收到此 C# 代码的错误

if (radioAll.Checked)
{
SqlDataSource DataSource2 = new SqlDataSource();
DataSource2.ID = "SqlDataSource2";
this.Page.Controls.Add(DataSource2);
DataSource2.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["SEP_Project_NewConnectionString2"].ConnectionString;
DataSource2.SelectCommand = "SELECT courseNo,title from Course";
gridview_modules.DataSource = DataSource2;
gridview_modules.DataBind();
}

报错如下 enter image description here

连接字符串没问题。如何修复此错误?

最佳答案

你必须从你的SqlDataSource中选择一些东西

gridview_modules.DataSource = DataSource2.Select(DataSourceSelectArguments.Empty);
gridview_modules.DataBind();

关于c# - 将数据源动态绑定(bind)到 gridview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17588114/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com