p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   ADO.NET (http://p2p.wrox.com/forumdisplay.php?f=109)
-   -   How to display checkbox in a DataGrid (http://p2p.wrox.com/showthread.php?t=17202)

kmazumdar August 20th, 2004 03:36 PM

How to display checkbox in a DataGrid

Another beginer's question :

I am still working on my very first form using ASp.NET and C# - so please bear with me.

I am fetching results into a DataGrid. One of the column has a Y or N value and I want show a Checkbox ( Checked if 'Y' and non-checked, if 'N'). I also need to change background color of the row, if the value is 'N'. Here is my ItemTemplate :

<asp:BoundColumn DataField="ACTIVE_IND" ItemStyle-HorizontalAlign="Center" HeaderText="Active Indicator"></asp:BoundColumn>
Data for this DataGrid is bound in the click event of a submit button.


DataGrid1.DataSource = ds.Tables["nnld"];

Thanks in advance.

mehdi62b August 23rd, 2004 09:47 AM

its not a beginer's question.!
I think you should have a checkbox somewhere like ItemTemplate and also you
fill your grid with your datasource,well
for getting what is bound to your filed you should work with
and also for changing the backcolor,you can work with yourDataGridItem.CssClass
and also you should have a <STYLE></STYLE> tag in your aspx file and set the CssClass
with one of the styles declared in your <STYLE> tag.
but where you can work with them?surely somewhere like DataGrid1_ItemDataBound
have a look at this example...

private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
if (e.Item.ItemType == ListItemType.Item ||
    e.Item.ItemType == ListItemType.AlternatingItem ||
    e.Item.ItemType == ListItemType.SelectedItem ||
    e.Item.ItemType == ListItemType.EditItem)

this example marks every item that aSpecialValue has been bound to it also change it's
CSS changes according to YourNewCssDecalredInStyleTag.


kmazumdar August 23rd, 2004 03:35 PM

Thank you. Let me try your suggestion.


All times are GMT -4. The time now is 09:23 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.