Currently my Grid shows True, False, or N/A in the cell for boolean values. What would be the way so that I can get it to show Yes, No, or blank? The users are somehow getting confused by True/False/NA.
I'm populating the Grid using a SQLDataSource tied to a stored procedure in a 2005 SQLServer database. Also, I am using a RowEditTemplate where the value is tied to a radiobutton group.
Thanks,
Will
Hello Will,
You can add a Template Field to WebDataGrid.Columns collection and put RadioButton in it.
<ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="400px"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1">
<Columns>
<ig:BoundDataField DataFieldName="id" Key="id">
<Header Text="id" />
</ig:BoundDataField>
<ig:TemplateDataField Key="TemplateField_0">
<ItemTemplate>
<asp:RadioButton ID="RadioButton1" runat="server" Text='<%# GetBool(Eval("IsChecked").ToString())%>' Checked='<%# Eval("IsChecked").ToString() == "True" ? true : false %>'/>
</ItemTemplate>
<Header Text="TemplateField_0" />
</ig:TemplateDataField>
</Columns>
</ig:WebDataGrid>
Also you have to add a method in code behind, which returns string value if the field is true, false or null:
protected string GetValue(string value)
{
if (value == "True")
return "Yes";
}
else
if (value == "False")
return "No";
return "Not Set";
Please let me know if you have any further questions with this matter.
Thank you
Sincerely,
Hristo Valyavicharski
Developer Support Engineer
Infragistics, Inc.
www.infragistcis.com/support
Thanks for the code!
Where are we using the GetValue method though? Maybe I'm missing something.
Hristo,
Thanks for your help! I didn't even think of using Eval. I changed mine to a label as I'm using a RowEditTemplate to edit the rows.
There's now an issue doing it this way. It's passing true as the value if the label is null so the Yes radio button in the RET is getting checked even though the value is null (not true or false). Below is some snippets. If it would help to get the full code, let me know and I'll attach
<igtbl:TemplatedColumn BaseColumnName="input_ops" IsBound="True" Key="input_ops">
<CellStyle HorizontalAlign="center"></CellStyle>
<HeaderStyle HorizontalAlign="center" />
<CellTemplate>
<asp:Label ID="lbl_ops" Width="40px" runat="server" Text='<%# GetValue(Eval("input_ops").ToString)%>' ></asp:Label>
</CellTemplate>
<Header Caption="OpsInfo?">
<RowLayoutColumnInfo OriginX="36" />
</Header>
<Footer>
</Footer>
</igtbl:TemplatedColumn>
//In uwg_BeforeRowTemplateOpen. row.getCell(36).getValue() is returning true even though the database value is null.
It would be nice if you post your source code.
Thanks
OK, here are the files for this page. Thanks for the help!
Will,
I modified your files but I couldn't run it because there is no database. Please test it and tell me what is the result.
Hristo, Thanks for your help with this issue. I definitely understood what you were going for, but I was trying to do it without having a radiobutton in the column. I finally stumbled upon using the actual cell text to trigger off of instead of the value of the cell to handling the checking of the radiobuttons in the RowEditTemplate. Now it works perfectly, and the grid column shows Yes, No, or blank instead of True, False, or blank.
var cell = row.getCell(36); var cell_text = cell.getElement().innerText.trim();
if(cell_text=='Yes') {rbOpsYes.checked=true;} else if(cell_text=='No') {rbOpsNo.checked=true;} else {rbOpsYes.checked=false; rbOpsNo.checked=false;}