c# - gridview绑定(bind)数据

标签 c# asp.net

我正在使用嵌套 GridView 。第二个应该使用存储过程进行绑定(bind)。存储过程的参数是 gridview1.selected 值,连接字符串应取自 config.connection string。我的代码是:

SqlCommand cmd = 
    new SqlCommand("spname", new SqlConnection(Config.connectionstring));
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("parametername", GridView1.SelectedValue);
cmd.Connection.Open();
control.DataSource = cmd.ExecuteReader();
control.DataBind();

但它不起作用。有什么想法吗?

最佳答案

你必须在前面的数据绑定(bind)的gridview事件上编写这个,在这个事件中你必须先找到控件然后绑定(bind)数据。

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

相关文章:

c# - 代码契约(Contract)在 Visual Studio 2010 Pro RC 中的属性

c# - 在 C# 中构建对象的更好方法

c# - 无法在 Visual Studio 2012 Professional 中导入数据库

c++ - qt soap 客户端 + ASP.net Web 服务

c# - ASP.NET 的 AOP 工具比较

asp.net - 在 asp.net MS 图表控件上显示工具提示

c# - 无法使用 C# ConfigurationManager

c# - 学习 System.Speech API 的好资源是什么?

c# - MongoDB 如何在单个查询中从集合的中间开始获取 K 个文档?

c# - 如何在 C# 中将逗号分隔的字符串绑定(bind)到列表框