Solved

gridview

Posted on 2009-05-18
8
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

724 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