Solved

gridview

Posted on 2009-05-18
8
227 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
ID: 24414274
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
ID: 24414286
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
ID: 24414327
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:Romacali
ID: 24414377
how can I add the code behind using a SqlDataReader? What do I have to have on the gridview aspx page?
0
 
LVL 26

Expert Comment

by:Anurag Thakur
ID: 24414379
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
ID: 24414386
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
ID: 24414396
you could put that code into the Page_Load event of the aspx page to get it firing.
0
 

Author Closing Comment

by:Romacali
ID: 31582683
thanks!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 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