Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET使用存储过程填充ListView_Asp.net_Data Binding - Fatal编程技术网

ASP.NET使用存储过程填充ListView

ASP.NET使用存储过程填充ListView,asp.net,data-binding,Asp.net,Data Binding,我正在尝试使用存储过程(@param1)填充ASP.NET LISTVIEW。如果可能的话,有人能告诉我吗。如果可能的话,If show me几行代码将非常有用。请参阅MSDN上的文章,该文章很好地展示了如何在web应用程序中使用SqlDataSource向支持数据的控件提供数据 基本上,您需要一个SqlDataSource <asp:SqlDataSource ID="sdsYourData" Runat="server" ProviderName="System.Data.Sq

我正在尝试使用存储过程(@param1)填充ASP.NET LISTVIEW。如果可能的话,有人能告诉我吗。如果可能的话,If show me几行代码将非常有用。

请参阅MSDN上的文章,该文章很好地展示了如何在web应用程序中使用
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>

它定义了连接到何处以获取数据(到存储的进程)-在这里,您需要确定如何在代码中填充该参数?是否从ASP.NET页上的另一个控件?根据这一点,您可以在
中使用其他元素

拥有数据源后,可以将列表视图连接到该数据源:

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

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

  • SQL存储过程中的哪些列将用于在列表视图中显示(
    DataTextField
  • 选择listview中的该行(
    DataValueField
    )时,SQL存储过程中的哪些列将向ASP.NET返回值