ASP.NET填充ListView控件与存储过程 [英] ASP.NET Populate ListView with Stored Procedure

查看:165
本文介绍了ASP.NET填充ListView控件与存储过程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用存储过程(@参数1)来填充 ASP.NET LISTVIEW 。任何人都可以请让我知道,如果有可能的。如果这是可能的,如果给我code的几行是非常有益的。

I'm trying to populate the ASP.NET LISTVIEW with Stored Procedure(@param1). Could anyone please let me know if it's possible at all. If it's possible, if show me few lines of code will be very helpful.

推荐答案

查看数据点:数据源中的ASP.NET控件在MSDN 2.0 的文章,其中很好地展示了如何使用的SqlDataSource 在你的Web应用程序提供数据给数据能够控制。

See the Data Points: Data Source Controls in ASP.NET 2.0 article on MSDN which nicely shows how to use the SqlDataSource in your web app to provide data to data-capable controls.

基本上,你需要一个SqlDataSource

Basically, you need a SqlDataSource

<asp:SqlDataSource ID="sdsYourData" Runat="server"
    ProviderName="System.Data.SqlClient"
    ConnectionString="Server=(local);Database=Northwind;Integrated Security=SSPI;"
    SelectCommand="dbo.YourStoredProcName" 
    <SelectParameters>
        <asp:Parameter Name="Param1" Type="String" />>
     </SelectParameters>
</asp:SqlDataSource>

这定义了连接,让您的数据(你的存储过程) - 在这里,你需要决定如何填补参数 - 在code?从你的ASP.NET页面上的另一个控制?根据所,你可能会使用其它元素融入到&LT; SelectParameters方式&gt;

that defines where to connect to to get your data (to your stored proc) - here, you'll need to determine how to fill that parameter - in code? From another control on your ASP.NET page? Depending on that, you might use other elements into <SelectParameters>.

一旦你的数据源,您可以将列表视图连接到它:

Once you have the data source, you can connect your list view to it:

<asp:ListView id="listView1" runat="server"
              DataSourceID="sdsYourData"
              DataTextField="SomeTextField" 
              DataValueField="YourIDField" />

在这里,你需要设置两个字段:

Here, you need to set two fields:


  • 从您的SQL存储过程中的列将被用于在列表视图中显示( DataTextField )?

  • 从您的SQL列当选择在ListView该行的存储过程将提供价值回ASP.NET( DataValueField )?

  • which of the columns from your SQL stored procedure will be used to display in the list view (DataTextField)?
  • which of the columns from your SQL stored procedure will provide the value back to ASP.NET when that row in the listview is selected (DataValueField)?

这篇关于ASP.NET填充ListView控件与存储过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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