Advertisement

04.24.2008 at 07:55AM PDT, ID: 23350462
[x]
Attachment Details

Gridview wont display data from stored procedure

Asked by garethh86 in .NET Framework 2.0, MS SQL Server, Microsoft Visual Basic.Net

Tags: VB.NET, SQL, ASP.NET

I have a page which allows users to enter details into text boxes and then a gridview to display results based on the entered data. I have a gridview which is supposed to display the returned data.

My stored procedure works fine testing from the sqldatasource but when the button is clicked the grid displays nothing.

Heres the sql statement (which I have tested and returns data ok).

(
      @FirstName NVARCHAR(50),
      @LastName NVARCHAR(50),
      @Email NVARCHAR(50),
      @PostCode NVARCHAR(50)
)

AS

      SELECT * FROM Customers
      WHERE FirstName LIKE @FirstName
      OR LastName LIKE @LastName
      OR EmailAddress LIKE @Email
      OR PostCode LIKE @PostCode

The SqlDataSource works fine, once completing the wizard it allows you to test by entering the variables and it returns the data. The gridview is set to this connector but upon clicking the button the page posts back but the gridview does nto display. I know the gridview wont appear if there is no data to display, where is it going wrong? Is the page posting back to quickly for the SQL server to return the data?

Thanks in advance!


Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
<table class="SearchCustIDTable">
    <tr>
        <td>First Name:</td>
        <td>
            <asp:TextBox ID="FName" runat="server"></asp:TextBox>
        </td>
        <td>Email Address:</td>
        <td>
            <asp:TextBox ID="EmailAdd" runat="server"></asp:TextBox>
        </td>
    </tr>
    <tr>
        <td>Last Name:</td>
        <td>
            <asp:TextBox ID="LName" runat="server"></asp:TextBox>
        </td>
        <td>Post Code:</td>
        <td>
            <asp:TextBox ID="PostCode" runat="server"></asp:TextBox>
                    </td>
    </tr>
    <tr>
        <td><asp:Button ID="Button1" runat="server" Text="Search" /></td>
    </tr>
    </table>
    </div>
        
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:MyConnectionString %>" 
            SelectCommand="FindCustID" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:ControlParameter ControlID="FName" Name="FirstName" PropertyName="Text" 
                    Type="String" />
                <asp:ControlParameter ControlID="LName" Name="LastName" PropertyName="Text" 
                    Type="String" />
                <asp:ControlParameter ControlID="EmailAdd" Name="Email" PropertyName="Text" 
                    Type="String" />
                <asp:ControlParameter ControlID="PostCode" Name="PostCode" PropertyName="Text" 
                    Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
            BackColor="LightGoldenrodYellow" BorderColor="Tan" BorderWidth="1px" 
            CellPadding="2" DataKeyNames="CustID" DataSourceID="SqlDataSource1" 
            ForeColor="Black" GridLines="None" style="font-size: small" EnableViewState="true">
            <FooterStyle BackColor="Tan" />
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="CustID" HeaderText="CustID" InsertVisible="False" 
                    ReadOnly="True" SortExpression="CustID" />
                <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
                    SortExpression="FirstName" />
                <asp:BoundField DataField="LastName" HeaderText="LastName" 
                    SortExpression="LastName" />
                <asp:BoundField DataField="Address1" HeaderText="Address1" 
                    SortExpression="Address1" />
                <asp:BoundField DataField="PostCode" HeaderText="PostCode" 
                    SortExpression="PostCode" />
                <asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
                <asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress" 
                    SortExpression="EmailAddress" />
                <asp:BoundField DataField="ContactTel" HeaderText="ContactTel" 
                    SortExpression="ContactTel" />
                <asp:BoundField DataField="DateJoined" DataFormatString="{0: dd/mm/yyy}" 
                    HeaderText="DateJoined" SortExpression="DateJoined" />
            </Columns>
            <PagerStyle BackColor="PaleGoldenrod" ForeColor="DarkSlateBlue" 
                HorizontalAlign="Center" />
            <SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
            <HeaderStyle BackColor="Tan" Font-Bold="True" />
            <AlternatingRowStyle BackColor="PaleGoldenrod" />
        </asp:GridView>
[+][-]04.24.2008 at 09:14AM PDT, ID: 21432497

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.24.2008 at 09:28AM PDT, ID: 21432636

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.27.2008 at 12:15PM PDT, ID: 21450077

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.27.2008 at 04:31PM PDT, ID: 21450752

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: .NET Framework 2.0, MS SQL Server, Microsoft Visual Basic.Net
Tags: VB.NET, SQL, ASP.NET
Sign Up Now!
Solution Provided By: garethh86
Participating Experts: 3
Solution Grade: B
 
 
[+][-]04.28.2008 at 08:00AM PDT, ID: 21454622

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.30.2008 at 06:50PM PDT, ID: 21475983

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628