Hi,
We have found the following behavior with Web Grid, and want to confirm if the same is a bug.
Created an Unbound column of CheckBox Type, and placed a 'Test Postback' on the page (outside the WebGrid).
Check one or more Check Boxes
Click 'Test Postback'
It works fine for the first postback.
User sees Check Boxes selected still.
Click 'Test Postback' again
This empties unchecks all Check Boxes in the Column.
Can somebody tell me if this behavior is by design or is a bug?
Also, is there any solution as we need to keep the CheckBox selection as is across all postbacks (Except converting the unbound column to a bound column and preserving its state in source data object).
Regards,
MPVBRao.
mpvbrao said:Also could you please explain the below. Why is the grid showing wrong checkbox state after first postback?, as the same state is not accessible though code in the next postback
Why is the grid showing wrong checkbox state after first postback?, as the same state is not accessible though code in the next postback
By persisting the state of the checkboxes, restoring them in either InitializeDataSource or InitializeLayout, you'll ensure that the checkboxes remain checked even after subsequent postbacks.
If you instead chose to not use InitializeDataSource, and so long as ViewState is enabled for the grid, the state of the checkboxes would be retrieved from ViewState. So long as you don't DataBind the grid again, the states will persist across multiple postbacks.
Ok, I will try to persist the state.
Also could you please explain the below.
Why is the grid showing wrong checkbox state after first postback?, as the same state is not accessible though code in the next postback.
Since you're using the InitializeDataSource event, the grid is implicitly calling DataBind() on every postback. Since you're not persisting the value in these checkboxes in any way, they're lost on the postback that occurs after the postback where they were changed.
I see two options. One is to persist the value of the checkbox on each row in some fashion. The other is to not use the InitializeDataSource event, and thus take direct control as to when you call the grid's DataBind() event.
No, there is no databind statement, as I am handling InitializeDataSource event
Thanks for the quick response.
Here is the complete code that reproduces the behavior.
Default.ASPX
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %>
<%@ Register Assembly="Infragistics35.WebUI.UltraWebGrid.v8.3, Version=8.3.20083.2021, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.WebUI.UltraWebGrid" TagPrefix="igtbl" @%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<igtbl:UltraWebGrid ID="samplesListView" runat="server" Height="90%" Width="100%">
<DisplayLayout AutoGenerateColumns="false" ViewType="Flat" AllowColSizingDefault="Free"
AllowColumnMovingDefault="OnServer" AllowDeleteDefault="Yes" AllowSortingDefault="Yes"
AllowUpdateDefault="Yes" BorderCollapseDefault="Separate" HeaderClickActionDefault="SortMulti"
Name="UltraWebGrid1" RowHeightDefault="20px" RowSelectorsDefault="No" SelectTypeRowDefault="Extended"
StationaryMargins="No" StationaryMarginsOutlookGroupBy="True" TableLayout="Fixed"
Version="4.00">
<FrameStyle BackColor="Window" BorderColor="InactiveCaption" BorderStyle="Solid"
BorderWidth="1px" Font-Names="Microsoft Sans Serif" Font-Size="8.25pt" Height="90%"
Width="100%">
</FrameStyle>
<Pager MinimumPagesForDisplay="1" PageSize="4" AllowPaging="true" PagerAppearance="Both"
StyleMode="QuickPages" QuickPages="5">
<PagerStyle BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">
<BorderDetails ColorLeft="White" ColorTop="White" WidthLeft="1px" WidthTop="1px" />
</PagerStyle>
</Pager>
<EditCellStyleDefault BorderStyle="None" BorderWidth="0px">
</EditCellStyleDefault>
<FooterStyleDefault BackColor="LightGray" BorderStyle="Solid" BorderWidth="1px">
</FooterStyleDefault>
<HeaderStyleDefault BackColor="LightGray" BorderStyle="Solid" HorizontalAlign="Left">
</HeaderStyleDefault>
<RowStyleDefault BackColor="Window" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px"
Font-Names="Microsoft Sans Serif" Font-Size="8.25pt">
<Padding Left="3px" />
<BorderDetails ColorLeft="Window" ColorTop="Window" />
</RowStyleDefault>
<GroupByRowStyleDefault BackColor="Control" BorderColor="Window">
</GroupByRowStyleDefault>
<GroupByBox>
<BoxStyle BackColor="ActiveBorder" BorderColor="Window">
</BoxStyle>
</GroupByBox>
<AddNewBox Hidden="False">
<BoxStyle BackColor="Window" BorderColor="InactiveCaption" BorderStyle="Solid" BorderWidth="1px">
</AddNewBox>
<ActivationObject BorderColor="" BorderWidth="">
</ActivationObject>
<FilterOptionsDefault FilterUIType="FilterRow" AllowRowFiltering="OnServer" RowFilterMode="AllRowsInBand">
<FilterDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid" BorderWidth="1px"
CustomRules="overflow:auto;" Font-Names="Verdana,Arial,Helvetica,sans-serif"
Font-Size="11px" Height="300px" Width="200px">
<Padding Left="2px" />
</FilterDropDownStyle>
<FilterHighlightRowStyle BackColor="#151C55" ForeColor="White">
</FilterHighlightRowStyle>
<FilterOperandDropDownStyle BackColor="White" BorderColor="Silver" BorderStyle="Solid"
BorderWidth="1px" CustomRules="overflow:auto;" Font-Names="Verdana,Arial,Helvetica,sans-serif"
Font-Size="11px">
</FilterOperandDropDownStyle>
</FilterOptionsDefault>
</DisplayLayout>
<Bands>
<igtbl:UltraGridBand DataKeyField="CompleteSampleNo">
<Columns>
<igtbl:TemplatedColumn Width="1%">
<Header Caption="Action">
</Header>
<CellTemplate>
<asp:LinkButton ID="testLinkButton1" runat="server" Text="Test DataKey" CommandName="test1"
CommandArgument='<%# DataBinder.Eval(Container.DataItem, "CompleteSampleNo") %>' />
|
<asp:LinkButton ID="testLinkButton2" runat="server" Text="Test CommandArgument" CommandName="test2"
</CellTemplate>
</igtbl:TemplatedColumn>
<igtbl:UltraGridColumn Key="CompleteSampleNo" BaseColumnName="CompleteSampleNo" Width="1%">
<Header Caption="Sample No.">
<RowLayoutColumnInfo OriginX="1"></RowLayoutColumnInfo>
<Footer>
</Footer>
</igtbl:UltraGridColumn>
<igtbl:UltraGridColumn Key="Select" Type="CheckBox" DataType="System.Boolean" Width="1%"
AllowUpdate="Yes">
<Header Caption="Select">
<RowLayoutColumnInfo OriginX="7" />
</Columns>
<AddNewRow View="NotSet" Visible="NotSet">
</AddNewRow>
</igtbl:UltraGridBand>
</Bands>
</igtbl:UltraWebGrid>
<asp:Button ID="testPostback" runat="server" Text="Test Postback" />
</div>
</form>
</body>
</html>
Default.ASPX.CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Infragistics.WebUI.UltraWebGrid;
using System.Configuration;
using System.Data;
using System.IO;
public partial class Default : System.Web.UI.Page
{
protected void Page_Init(object sender, EventArgs e)
this.samplesListView.InitializeDataSource += new InitializeDataSourceEventHandler(samplesListView_InitializeDataSource);
}
public class Sample
public int Batch { get; set; }
public int SampleNumber { get; set; }
public string CompleteSampleNo
get
return string.Format("{0}-{1}", this.Batch, this.SampleNumber);
private void AddSamples(List<Sample> samplesList, int batch, int numberOfSamples)
for (int i = 1; i <= numberOfSamples; i++)
samplesList.Add(new Sample() { Batch = batch, SampleNumber = i });
void samplesListView_InitializeDataSource(object sender, UltraGridEventArgs e)
//prepare some dummy data for the grid
var batchesList = new List<Sample>();
AddSamples(batchesList, 112333, 4);
AddSamples(batchesList, 112334, 3);
AddSamples(batchesList, 112335, 1);
AddSamples(batchesList, 112336, 4);
samplesListView.DataSource = batchesList;
That's odd.
Are you re-binding your grid during a postback, such as in the Page_Load event?