Solved

gridview

Posted on 2009-05-18
8
223 Views
Last Modified: 2012-05-07
Hello,

I have a grid view on my page and it should display data from my stored procedure. How can I setup it up? I have a datasource and it is not what I need.. please need some help.


<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" EmptyDataText="No Evaluation were found for this participant" DataSourceID="SqlDataSource1" BackColor="White" BorderColor="#ffffff" BorderStyle="1" BorderWidth="1px" CellPadding="3" GridLines="Vertical">

            <Columns>

            <asp:TemplateField Visible="False"><ItemTemplate>

                        <asp:Label ID="lblEvaluationVisitID" runat="server" Text='<%# Eval("EvaluationVisitID") %>' />

                    </ItemTemplate></asp:TemplateField>

                 <asp:BoundField  DataField="EvaluationVisitID" HeaderText="Evaluation Visit ID" />

                <asp:BoundField  DataField="ParticipantID" HeaderText="Participant ID" />

                <asp:BoundField  DataField="EvaluationID" HeaderText="EvaluationID" />

                <asp:BoundField  DataField="DateEvaluation" HeaderText="Date of Evaluation" />

            

     <asp:TemplateField ShowHeader="False"><ItemTemplate>

                <asp:ImageButton ID="lnkSelect2" runat="server" ImageUrl="~/Images/icons/pencil.gif" ToolTip="Edit"  />

                <%--<asp:ImageButton ID="lnkDelete" runat="server"  CommandArgument='<%# Eval("EvaluationVisitID") %>' ImageUrl="~/Images/icons/cross.gif" ToolTip="Delete" />--%>

                    

                </ItemTemplate></asp:TemplateField>

            </Columns>

 </asp:GridView>
 

<!-- data sources -->

   <asp:SqlDataSource ID="SqlDataSource1" runat="server"  SelectCommand="SELECT [EvaluationVisitID], [ParticipantID],[EvaluationID],[DateEvaluation] FROM [tbl_EvaluationVisit]" ConnectionString="<%$ ConnectionStrings:%>" ></asp:SqlDataSource>

    <!-- /data sources -->

Open in new window

0
Comment
Question by:Romacali
  • 3
  • 3
  • 2
8 Comments
 
LVL 26

Expert Comment

by:Anurag Thakur
Comment Utility
how to use a sqldatasource with a stored procedure

<asp:SqlDataSource id="dsGetData" runat="server" SelectCommand="sp_name" SelectCommandType="StoredProcedure" ConnectionString="<%$ ConnectionStrings:ciscoConnectionString %>">
</asp:SqlDataSource>

the sp will return a table and the column names of the table should match the datafield in the bound field
0
 
LVL 12

Accepted Solution

by:
GuitarRich earned 500 total points
Comment Utility
link it up in the code behind using a SqlDataReader

SqlConnection conn = new SqlConnection(yourConnectionString);

SqlCommand comand = new SqlCommand("StoredProcedureName", conn);

// Add your parameters here

command.Parameters.AddWithValue(...);
 

conn.Open();

SqlDataReader reader = command.ExecuteReader();
 

GridView1.DataSource = reader;

GridView1.DataBind();
 

reader.Close();

conn.Close();

Open in new window

0
 

Author Comment

by:Romacali
Comment Utility
cool.. now I got this error:

Procedure 'sp_GetAllEvaluationVisit' expects parameter '@ParticipantID', which was not supplied.

How can I pass this parameter to the procedure?.. it is a field on this page being retrieve called txtParticipantID and it is int also can be the Request.QueryString["r"]

0
 

Author Comment

by:Romacali
Comment Utility
how can I add the code behind using a SqlDataReader? What do I have to have on the gridview aspx page?
0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 26

Expert Comment

by:Anurag Thakur
Comment Utility
you have to pass the paramets to the sp as its expecting the parameter
have a look at the following msdn link
http://msdn.microsoft.com/en-us/library/z72eefad.aspx
0
 
LVL 12

Expert Comment

by:GuitarRich
Comment Utility
add the parameters to the command object - I included a section in the above code. To add that parameter do it like this:
command.Parameters.AddWithValue("@ParticipantID", txtParticipantID.Text);

Open in new window

0
 
LVL 12

Expert Comment

by:GuitarRich
Comment Utility
you could put that code into the Page_Load event of the aspx page to get it firing.
0
 

Author Closing Comment

by:Romacali
Comment Utility
thanks!
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
This video discusses moving either the default database or any database to a new volume.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now