ASP。用存储过程填充ListView

时间:2022-09-20 23:22:09

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 LISTVIEW (@param1)。如果可能的话,谁能告诉我一声。如果可能的话,给我看几行代码会很有帮助。

1 个解决方案

#1


3  

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.

参见数据点:ASP中的数据源控件。NET 2.0关于MSDN的文章,它很好地展示了如何在web应用程序中使用SqlDataSource向具有数据能力的控件提供数据。

Basically, you need a SqlDataSource

基本上,您需要一个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>

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>.

它定义了在何处连接以获取数据(到存储的proc)——在这里,您需要确定如何在代码中填充该参数?来自ASP的另一个控件。网络页面?根据这一点,您可以在 中使用其他元素。

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

一旦有了数据源,就可以将list视图连接到它:

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

Here, you need to set two fields:

这里需要设置两个字段:

  • which of the columns from your SQL stored procedure will be used to display in the list view (DataTextField)?
  • SQL存储过程中的哪些列将用于在列表视图(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)?
  • 您的SQL存储过程中的哪些列将为ASP提供值。当listview中的行被选中时(DataValueField)?

#1


3  

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.

参见数据点:ASP中的数据源控件。NET 2.0关于MSDN的文章,它很好地展示了如何在web应用程序中使用SqlDataSource向具有数据能力的控件提供数据。

Basically, you need a SqlDataSource

基本上,您需要一个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>

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>.

它定义了在何处连接以获取数据(到存储的proc)——在这里,您需要确定如何在代码中填充该参数?来自ASP的另一个控件。网络页面?根据这一点,您可以在 中使用其他元素。

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

一旦有了数据源,就可以将list视图连接到它:

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

Here, you need to set two fields:

这里需要设置两个字段:

  • which of the columns from your SQL stored procedure will be used to display in the list view (DataTextField)?
  • SQL存储过程中的哪些列将用于在列表视图(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)?
  • 您的SQL存储过程中的哪些列将为ASP提供值。当listview中的行被选中时(DataValueField)?