I have a grid that binds on !IsPostBack in Page_Load, the grid has a GridClientDeleteColumn column with AutoGenerateColumns="true". Everything works great until I start binding the grid on ClientSide, then I lose the GridClientDeleteColumn icon and functionality for the grid (only the new row do not have the GridClientDeleteColumn icon), however if I do a post-back on the page then any client side binding after will have the GridClientDeleteColumn.
The reason I am binding at Page_Load is so I get all the column names from my data object. After the initial first bind (on server side), I am binding from the client side for speed so I don't have to do a full post back after I add/delete/modify my grid data rows.
Code:
ASPX code
-----------------------------------------------------------------------------------------------------------
<script language="javascript">
function AddProduct(productID){
var myGrid = $find("<%=myGrid.ClientID%>");
PageMethods.AddProduct(productID, OnSucceeded,OnFailed);
myGrid.MasterTableView.rebind();
}
function OnSucceeded(result, userContext, methodName) {
...
}
function OnFailed(error, userContext, methodName) {
...
}
</script>
<telerik:RadGrid ID="myGrid" runat="server" AllowAutomaticUpdates="True"
AllowFilteringByColumn="False" AllowPaging="False" AllowSorting="True"
AutoGenerateColumns="True" EnableEmbeddedSkins="false" EnableViewState="False"
FilterItemStyle-HorizontalAlign="Left" GridLines="None"
GroupHeaderItemStyle-HorizontalAlign="Left"
PageSize="25" ShowFooter="True" EnableClientKeyValues="true"
ShowGroupPanel="false" ShowStatusBar="True" Skin="Sunset">
<clientsettings allowcolumnsreorder="False" allowdragtogroup="False"
reordercolumnsonclient="False">
<clientevents OnRowDeleting="RowDeleting"></clientevents>
<selecting allowrowselect="false" />
<DataBinding Location="MyPage.aspx"
SelectMethod="GetData" SortParameterType="String" EnableCaching="false"
DataPropertyName="Data" CountPropertyName="Count" />
</clientsettings>
<mastertableview clientdatakeynames="ProductID"
datakeynames="ProductID" name="MasterTableView">
<columns>
<telerik:GridClientDeleteColumn ConfirmText="Delete this item?" ButtonType="ImageButton"
ImageUrl="delete.gif" CommandName="Delete" Text="Delete">
</telerik:GridClientDeleteColumn>
<telerik:GridBoundColumn UniqueName="ProductID" DataField="ProductID" HeaderText="ProductID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="ProductName" DataField="ProductName" HeaderText="Product Name">
</telerik:GridBoundColumn>
</columns>
</mastertableview>
</telerik:RadGrid>
Add Test Product: <input type="button" id="btnClientButton" onclick="AddProduct(12345)">
<asp:Button id="btnServerButton" OnClick="btnServerButton_Click" runat="server" Text="Do a Post Back Then Everything is A-OK">
-----------------------------------------------------------------------------------------------------------
Server Side Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
myGrid.DataSource=GetData("")["Data"];
myGrid.DataBind();
}
}
[WebMethod(true)]
public static Dictionary<string,object> GetData(string sortExpression)
{
.
.
data.add("Data",objDataList);
data.add("Count",objDataList.Count);
return data;
}
[WebMethod(true)]
public static bool AddProduct(int productID)
{
.
.
objDataList.Add(productID)
return true;
}
Why is it that only when there's a post back (at least one post back) then the GridClientDeleteColumn will show when I do a client databind/rebind?
The reason I am binding at Page_Load is so I get all the column names from my data object. After the initial first bind (on server side), I am binding from the client side for speed so I don't have to do a full post back after I add/delete/modify my grid data rows.
Code:
ASPX code
-----------------------------------------------------------------------------------------------------------
<script language="javascript">
function AddProduct(productID){
var myGrid = $find("<%=myGrid.ClientID%>");
PageMethods.AddProduct(productID, OnSucceeded,OnFailed);
myGrid.MasterTableView.rebind();
}
function OnSucceeded(result, userContext, methodName) {
...
}
function OnFailed(error, userContext, methodName) {
...
}
</script>
<telerik:RadGrid ID="myGrid" runat="server" AllowAutomaticUpdates="True"
AllowFilteringByColumn="False" AllowPaging="False" AllowSorting="True"
AutoGenerateColumns="True" EnableEmbeddedSkins="false" EnableViewState="False"
FilterItemStyle-HorizontalAlign="Left" GridLines="None"
GroupHeaderItemStyle-HorizontalAlign="Left"
PageSize="25" ShowFooter="True" EnableClientKeyValues="true"
ShowGroupPanel="false" ShowStatusBar="True" Skin="Sunset">
<clientsettings allowcolumnsreorder="False" allowdragtogroup="False"
reordercolumnsonclient="False">
<clientevents OnRowDeleting="RowDeleting"></clientevents>
<selecting allowrowselect="false" />
<DataBinding Location="MyPage.aspx"
SelectMethod="GetData" SortParameterType="String" EnableCaching="false"
DataPropertyName="Data" CountPropertyName="Count" />
</clientsettings>
<mastertableview clientdatakeynames="ProductID"
datakeynames="ProductID" name="MasterTableView">
<columns>
<telerik:GridClientDeleteColumn ConfirmText="Delete this item?" ButtonType="ImageButton"
ImageUrl="delete.gif" CommandName="Delete" Text="Delete">
</telerik:GridClientDeleteColumn>
<telerik:GridBoundColumn UniqueName="ProductID" DataField="ProductID" HeaderText="ProductID">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="ProductName" DataField="ProductName" HeaderText="Product Name">
</telerik:GridBoundColumn>
</columns>
</mastertableview>
</telerik:RadGrid>
Add Test Product: <input type="button" id="btnClientButton" onclick="AddProduct(12345)">
<asp:Button id="btnServerButton" OnClick="btnServerButton_Click" runat="server" Text="Do a Post Back Then Everything is A-OK">
-----------------------------------------------------------------------------------------------------------
Server Side Code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
myGrid.DataSource=GetData("")["Data"];
myGrid.DataBind();
}
}
[WebMethod(true)]
public static Dictionary<string,object> GetData(string sortExpression)
{
.
.
data.add("Data",objDataList);
data.add("Count",objDataList.Count);
return data;
}
[WebMethod(true)]
public static bool AddProduct(int productID)
{
.
.
objDataList.Add(productID)
return true;
}
Why is it that only when there's a post back (at least one post back) then the GridClientDeleteColumn will show when I do a client databind/rebind?