I have a boolean value in a datatable that i bind to a datagrid from the codebehind. But instead of a checkbox the webDataGrid displays "true" or "false" and that column is editable like a string value.
Here is some code that i'm using (_sestevalniDT is a DataTable and SestevalniStevec is a WebDataGrid):
_sestevalniDT = new DataTable();
_sestevalniDT.Columns.Add(new DataColumn("Naziv", typeof(string)));
_sestevalniDT.Columns.Add(new DataColumn("Popravek", typeof(bool)));
...SestevalniStevec.DataSource = _sestevalniDT;
SestevalniStevec.DataBind();
and this is from my aspx:
<ig:WebDataGrid ID="SestevalniStevec" runat="server" StyleSetName="Appletini" Width="640" Height="480" DataKeyFields="Naziv"> <Behaviors> <ig:ColumnResizing Enabled="true"> <ColumnSettings> <ig:ColumnResizeSetting EnableResize="true" /> </ColumnSettings> </ig:ColumnResizing> <ig:EditingCore> <Behaviors> <ig:CellEditing Enabled="true" EditModeActions-MouseClick="Single"> <CellEditingClientEvents EnteringEditMode="svoEnteringEditMode" /> </ig:CellEditing> </Behaviors> </ig:EditingCore> </Behaviors> </ig:WebDataGrid>
What should i add in order for the bool value to display as a checkbox?
Thanks for your help.
I'm not sure if you're experiencing the null problem, but I took a shot.
Hi,
Just have a server side sub around the data to check if it's null like this:
<ig:TemplateDataField Key="FormSheeted" Width="7%" > <ItemTemplate> <asp:CheckBox ID="CheckBox" AutoPostBack="true" OnCheckedChanged="CheckBox_CheckedChanged" runat="server" Checked='<%# sheeted(DataBinder.Eval(CType(Container, Infragistics.Web.UI.TemplateContainer).DataItem, "FormSheeted")) %>' /> </ItemTemplate> <Header Text="Form Sheeted" /></ig:TemplateDataField>
and on the server side you have:
Protected Function Sheeted(ByVal SheetedVal As Object) As Boolean ' used in markup If IsDBNull(SheetedVal) Then Return False Else Return CType(SheetedVal, Boolean) End If End Function
Ed
Hi, did you ever figure why you got the not supported error.
I have a webDataGrid and a WebHierarchicalDataGrid that work fine until I bind the boolean column to a checkbox column, then when it gets to the DataBind() it says that method is not supported.
Any Help would be appreciated!
It worked just like I needed. Thanks a lot for sharing this information, you have no idea how much you've helped me! :)
Hello!
I got a solution to my problem on Infragistics Support, it is a lot more helpful than the forum. Here are the replies i got to my questions:
Thank you for contacting Infragistics support.
In order to display the Boolean value as CheckBox you have to create template column.
By default the AutoGenerateColumns property is set to True
and the WebDataGrid is automatically creating all the columns from the datasource
<Columns>
<ig:TemplateDataField Key=" boolColumn">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"
Checked='<%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "boolColumn") %>'>
</asp:CheckBox>
</ItemTemplate>
<Header Text="boolColumn" />
</ig:TemplateDataField>
</Columns>
Here you can find more information regarding the usage of item template in the online documentation:http://help.infragistics.com/NetAdvantage/ASPNET/2010.1/CLR3.5/?page=WebDataGrid_Using_Item_Template.html
Thank you for the update.The best option to update the data source is inside the CheckedChanged event of the CheckBox.Below there is sample code how you can do this:
protected void Page_Load(object sender, EventArgs e)
{
if (Session["data"] != null)
DataTable data = (DataTable)Session["data"];
WebDataGrid1.DataSource = data;
}
else {
DataTable table = MakeTable();
WebDataGrid1.DataSource = table;
Session["data"] = table;
protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
CheckBox chk = (CheckBox)sender;
TemplateContainer parent = (TemplateContainer)chk.Parent;
DataRowView dataItem = (DataRowView)parent.DataItem;
DataRow row = dataItem.Row;
row.SetField("bool", chk.Checked);
Session["data"] = WebDataGrid1.DataSource;