Search code examples
c#jqueryasp.netsqldatasourcejqgrid-asp.net

jqGrid + SqlDataSource Post Back Problem


I'm using jqGrid in an asp.net page.

It is bound to an SqlDataSource object in the markup file, but I set the SelectCommand of this SqlDataSource on Page_Load in code-behind, ie:

    <asp:SqlDataSource runat="server" ID="SqlDataSource1"  
    ConnectionString="<%$ ConnectionStrings:FooDatabase %>" > 
    </asp:SqlDataSource>     

    <cc1:JQGrid runat="server" ID="JQGrid1" DataSourceID="SqlDataSource1"  
        Width="600px" Height="462px" onsearch="JQGrid1_Searching" 
        PagerSettings-PageSize="20" > 


    protected void Page_Load(object sender, EventArgs e)
    {
        SqlDataSource1.SelectCommand =
            "SELECT [Foo] From [FooTable]", 
    }

This works fine.

But when I assign the same SelectCommand in a button click event no data loads into the jqGrid. Ie:

    protected void btn_Submit_Click(object sender, EventArgs e)
    {
        SqlDataSource1.SelectCommand =
            "SELECT [Foo] FROM [FooTable]"
    } 

I've tried calling JQGrid.DataBind() on postback, but that didnt work.

Any thoughts?


Solution

  • Solved this. Have to assign the sql command inside the grid's DataRequesting event,

        protected void JqGrid_Requesting(object sender, Trirand.Web.UI.WebControls.JQGridDataRequestEventArgs e)
        { 
            if (Session["Cmd"] != null)
            {
                SqlDataSource1.SelectCommand = Session["Cmd"] as string; 
            }
        }
    

    See following link : http://www.trirand.net/forum/default.aspx?g=posts&t=23