views:

396

answers:

2

I have really weird situation. I've created new aspx page, and without using ANY custom logic objects (everything created with visual studios wizards) tried to create grid view from sqldatasource.

The data comes from stored procedure, with single parameter which has default value. when I refresh the schema or click "test query", I see result rows and GridViews fields are corectly created. But when I run the page there is no grid view (it's simply empty - when I add EmptyDataTemplate it is shown) . I've added custom (empty) function and DataBind, DataBinded and RowCreted event, and only databind and datavound events are fired (although, as I wrote - the stored procedure with its default parameter return rows and .net can read them in design mode)

There isn't anything "fancy" in the procedure, I've done this more than once with no problem. I've tried another stored procedure wich works in our production env and still got the same emty gridview

here is the code

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="TEST.aspx.cs" Inherits="site.TEST" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<html xmlns="http://www.w3.org/1999/xhtml"&gt;
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1"
            AllowSorting="True" OnDataBinding="GridView1_DataBinding" OnDataBound="GridView1_DataBound"
            OnRowCreated="GridView1_RowCreated">
            <EmptyDataTemplate>
                No Data Available
            </EmptyDataTemplate>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>"
            SelectCommand="myStoredProcedure" SelectCommandType="StoredProcedure">
            <SelectParameters>
                <asp:Parameter DefaultValue="val1" Name="par1" Type="String" />
                <asp:Parameter Name="val2" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    </div>
    </form>
</body>
</html>

and the codebehind

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace site
{
    public partial class TEST : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {//brake here

        }

        protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {//brake here

        }

        protected void GridView1_DataBinding(object sender, EventArgs e)
        {//brake here

        }

        protected void GridView1_DataBound(object sender, EventArgs e)
        {//brake here

        }
    }
}
A: 

I haven't see assignment of parameters(val1, val2), so default launch will assign default for string and int and pass to SQL server.

Try SQL Server Profiler to see if you execute selection with REAL parameters

Dewfy
Paramters are passas they should (with default value on the first and no value (has default value in the stored procedure itself) It looks like there is no connection to the DB (the profiler didn't show the BatchStarting Event, but when i executed the procedure from the managamnet studio - it showed up)
TheSimon
+4  A: 

From your recent comments it looks as though SQL Profiler isn't showing any activity when the SelectCommand is issued from the SqlDataSource. This could be due to the fact that ConvertEmptyStringToNull is set to true by default on Parameters contained in the SelectParameters collection. Also, by default, the CancelSelectOnNullParameter on the SqlDataSource is set to true. This means that your 'val2' parameter is probably passing a NULL value, which in turn cancels the data retrieval operation. This is why you don't see any activity within SQL Profiler.

Try setting CancelSelectOnNullParameter to false on the SqlDataSource.

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:myConnectionString %>" SelectCommand="myStoredProcedure" SelectCommandType="StoredProcedure" CancelSelectOnNullParameter="False"> </asp:SqlDataSource>

Phaedrus
You can't imagine how thankfull I am :)
TheSimon