I'm trying to populate the ASP.NET LISTVIEW with Store开发者_开发百科d 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.
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.
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>
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:
- 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
)?
精彩评论