This is a migrated thread and some comments may be shown as answers.

Posting back from a checkbox column is making the grid disappear in the latest version Q1 2014

3 Answers 7 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Zafar
Top achievements
Rank 1
Zafar asked on 02 May 2014, 07:26 PM
Hello,
I am trying to upgrade from, I believe, Q3 2010 to the latest version Q1 2014. I have made everything work except one place where I have the grid in edit mode with a checkbox column wired to auto post back. When I click on the checkbox, the grid disappears. I have created a small test project to replicate this behavior and hoping you guys can help me resolve this issue. This scenario is working just fine with the old version.

Below is the test code I have created to replicate this issue.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="GridTest.aspx.cs" Inherits="RadGridTest.GridTest" %>
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>

<h1> Rad Grid Test</h1>
<hr/>
<br /><br />

<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns ="false" AllowMultiRowEdit="true" OnItemCreated="RadGrid1_ItemCreated" OnPreRender="RadGrid1_PreRender">

<MasterTableView EditMode="InPlace" DataKeyNames="AuditId, CheckId">

<Columns>
<telerik:GridBoundColumn UniqueName="AuditId" HeaderText="AuditId" DataField="AuditId" ReadOnly="true" Display="false" />
<telerik:GridBoundColumn UniqueName="CheckId" HeaderText="CheckId" DataField="CheckId" ReadOnly="true" Display="false" />
<telerik:GridCheckBoxColumn UniqueName="CompletionStatus" HeaderText="Status" DataField="CompletionStatus"/>
<telerik:GridBoundColumn UniqueName="Check" HeaderText="Check" DataField="Check" ReadOnly="true" />
<telerik:GridBoundColumn UniqueName="Comments" HeaderText="Comments (if any)" DataField="Comments"/>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</div>
</form>
</body>
</html>



using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;

namespace RadGridTest
{
public partial class GridTest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
var audit = new Audit();
RadGrid1.DataSource = audit.Checks;
}
}

protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = (GridDataItem)e.Item;
CheckBox chkbox = (CheckBox)item["CompletionStatus"].Controls[0];
chkbox.AutoPostBack = true;
chkbox.CheckedChanged += new EventHandler(chkbox_CheckedChanged);
}
}

void chkbox_CheckedChanged(object sender, EventArgs e)
{

}

protected void RadGrid1_PreRender(object sender, EventArgs e)
{
RadGrid grd = (RadGrid)sender;
foreach (GridItem item in grd.MasterTableView.Items)
{
if (item is GridEditableItem)
{
GridEditableItem editableItem = item as GridDataItem;
editableItem.Edit = true;
}
}
grd.Rebind();
}
}

public class Audit
{
public int AuditId { get; set; }
public int CheckId { get; set; }
public bool CompletionStatus { get; set; }
public string Check { get; set; }
public string Comments { get; set; }

public List<Audit> Checks
{
get
{
var lst = new List<Audit>();
lst.Add(new Audit { AuditId = 1, CheckId = 1, CompletionStatus = false, Check = "Test1" });
lst.Add(new Audit { AuditId = 1, CheckId = 2, CompletionStatus = false, Check = "Test2" });
lst.Add(new Audit { AuditId = 1, CheckId = 3, CompletionStatus = false, Check = "Test3" });
return lst;
}
}
}
}




Thanks,

Zafar

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 05 May 2014, 05:44 AM
Hi Zafar,

Please use the NeedDataSource event to bind your radgrid. When you have the grid to perform complex operations such as Inserting, deleting, and updating records through custom edit forms (WebUserControl or FormTemplate)Grouping, Hierarchy relations, Filtering, Sorting, Paging etc, you have to use NeedDataSource event. Also set the grid in editmode in PreRender inside "!IsPostBack", else the grid will always be rebinded on postback.

C#:
protected void RadGrid1_PreRender(object sender, EventArgs e)
{
    RadGrid grd = (RadGrid)sender;
    if (!IsPostBack)
    {
        foreach (GridDataItem dataItem in grd.MasterTableView.Items)
        {           
          dataItem.Edit = true;          
        }
        grd.Rebind();
    }
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    var audit = new Audit();
    RadGrid1.DataSource = audit.Checks;
}

Thanks,
Princy
0
Zafar
Top achievements
Rank 1
answered on 06 May 2014, 12:09 AM
Hi Princy,

Thank you for your help. My actual scenario is quite complex than this sample I created. I have the grid in a formview control and the formview gets its record when a row is selected in a top level summary grid. I am binding the grid in the databound event of the formview where I have access to the data item of the formview control.

After some experiments, it seems to me that in my this particular scenario, the binding is working ok but as you pointed out, putting grid rows in the edit mode and rebind in the prerender event without "!IsPostBack" is what causing the issue. Since the grid in my case is in the formview, it is always going to be bind in the postback and thus I can't just use !IsPostBack and might have to figure out a way that not do the rebind only when it is coming through by clicking on the checkbox column in the grid or something.

Though my question is that this same code works fine with the old version of Telerik controls but gives this issue when using the latest version of the Telerik Controls. Has some behavior changed in the later versions to give me this issue? The old Telerik version I am using with which this works fine is 2010.3.1317.40.

Thanks,

Zafar



0
Princy
Top achievements
Rank 1
answered on 06 May 2014, 04:05 AM
Hi Zafar,

You can have a look at the release history to know about the changes or new functionality added on to each versions. Release History Q1 2014 (version 2014.1.225).

Thanks,
Princy
Tags
Grid
Asked by
Zafar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Zafar
Top achievements
Rank 1
Share this question
or