asp.net - 从存储过程获取结果以填充 GridView

标签 asp.net data-binding gridview

我有一个 Windows aspx 表单,其中有一个 TextBoxButton 和一个 GridViewTextBox 存储为变量 @subschedule 并传递给存储过程。我想做的就是将该过程的结果填充到我的 GridView 中。谁能建议一种方法来做到这一点?

谢谢

最佳答案

两个流行的选项:

1..隐藏代码:

string subSchedule = txtSubSchedule.Text.Trim();

//you'll create a new class with a method to get a list of customers
//from your database as others answers have demonstrated
IEnumerable<Customer> custs = MyDataLayer.GetCustomers(subSchedule);

myGrid.DataSource = custs;
myGrid.DataBind();

2..使用SqlDataSource。这是将 ASP.NET 服务器控件绑定(bind)到存储过程的一种快速但肮脏的方法。它有易于实现的优点,但也有一些其他缺点:

 <asp:GridView  id="myGrid"
            runat="server"
            AutoGenerateColumns="true"
            DataSourceID="ds1" />

        <asp:SqlDataSource
            id="ds1"
            runat="server"
            ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
            SelectCommandType="StoredProcedure"                
            SelectCommand="GetSchedule">
              <SelectParameters>
                  <asp:ControlParameter name="SubSchedule" 
                          ControlID="txtSubSchedule" Propertyname="Text"/>
              </SelectParameters>
        </asp:SqlDataSource>

关于asp.net - 从存储过程获取结果以填充 GridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5199534/

相关文章:

asp.net - 使用声明性数据绑定(bind) ASP.NET 进行评估

android - GridView 在 notifyDataSetChanged() 之后没有更新

javascript - 从后面的代码中调用 javascript 的函数

c# - 为车身参数生成描述字段

c# - WPF MVVM 我可以从 View 中使用模型吗

c# - 数据绑定(bind)、多线程和单元测试

c# - WPF GridView : Determining held item

Android GridView 垃圾收集 (GC_EXTERNAL_ALLOC) <1K 过热,导致 UI 非常不稳定

c# - 正则表达式查找 Href 值

asp.net - 如何更改用户控件中的默认标签前缀