BindingOperationMode="ClientBinding" PrepareDataBinding doesn't run and grid show blank

3 replies. Last post: January 27, 2015 2:31 AM by Yudi
Tags :
  • (None)
  • New Discussion
  • New Question
  • New Product Feedback
Alan TranMember
Hi Intersoft,

I try to upgrade my webgrid from 6 to 9 using ClientBinding technology for best performance.

But I found the issue that when using BindingOperationMode="ClientBinding" with PrepareDataBinding to build columns structure, it doesn't work.

When the first time load (IsPostBack is false), WebGrid doesn't call PrepareDataBinding method. Hence the grid show data in blank (no column in client side).

This is my sample
File Default.aspx.cx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using ISNet.WebUI.WebGrid;

namespace TestWebGrid
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void WebGrid1_InitializeDataSource(object sender, ISNet.WebUI.WebGrid.DataSourceEventArgs e)
        {
            DataTable dt = new DataTable();

            dt.Columns.Add(new DataColumn("CustomerID", typeof(string)));
            dt.Columns.Add(new DataColumn("CompanyName", typeof(string)));
            dt.Columns.Add(new DataColumn("Phone", typeof(string)));

            //if (((ISNet.WebUI.WebGrid.WebGrid)(sender)).ActionName == PostBackAction.LoadData)
            //{                  
                for (int i = 1; i <= 20; i++)
                    dt.Rows.Add(new object[] { i.ToString(), "Company " + i.ToString(), "12345678" + i.ToString() });
            //}
            e.DataSource = dt;
        }

        protected void WebGrid1_PrepareDataBinding(object sender, DataSourceEventArgs e)
        {
            WebGrid1.RetrieveStructure();
        }        
    }
}

  File Default.aspx

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

<%@ Register assembly="ISNet.WebUI.WebGrid" namespace="ISNet.WebUI.WebGrid" tagprefix="ISWebGrid" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
        <ISWebGrid:WebGrid ID="WebGrid1" runat="server" Height="250px" UseDefaultStyle="True" Width="500px"                        
            BindingOperationMode="ClientBinding" OnInitializeDataSource="WebGrid1_InitializeDataSource" OnPrepareDataBinding="WebGrid1_PrepareDataBinding">
            <LayoutSettings AllowContextMenu="False" ContextMenuAnimation="False" AlwaysShowHelpButton="False">                 
            </LayoutSettings>                    
        </ISWebGrid:WebGrid>               
    </div>
    <div>

    </div>
    </form>
</body>
</html>

 

Regards

All times are GMT -5. The time now is 2:10 AM.
Previous Next