• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 545
  • Last Modified:

ASP.net Populating the GridView from data from a Stored Procedure

I am programming in ASP.Net and my form is just a search in the database that returns data to a gridview. I am using a stored procedure that that assembles the sql statemnet based on the parameters and excutes that SQL. The last line of the Stored Procedure is EXEC(@SQL). @SQL is just a varaible that contains the full select statement based on user options. The problem that I am having is that I donot know how to populate the gridview with the data from the stored procedure.
1 Solution
Have you tried using a SQL Data Source that calls your stored procedure and then binding to that datasource?

<asp:gridview runat="server" id="mySPGV" DataSourceId="spDataSource" />

<asp:SqlDataSource ID="spDataSource" runat="server" ConnectionString="yourConnection"
      ProviderName="yourProvider" SelectCommandType="StoredProcedure">
      <asp:ControlParameter ControlID="myTextBoxValueForSQL" Name="SQL" PropertyName="Text" />

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now