Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 20th, 2004, 03:36 PM
Registered User
 
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to display checkbox in a DataGrid

Hi,

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 :
Code:
<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.

Code:
DataGrid1.DataSource = ds.Tables["nnld"];
DataGrid1.DataBind();
Thanks in advance.


 
Old August 23rd, 2004, 09:47 AM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

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
yourDataGridItem.DataItem.
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...
Code:
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)
        {    
            if(((DataRowView)e.Item.DataItem).Row.ItemArray[0].ToString()=="aSpecialValue")
            {
                ((CheckBox)e.Item.Cells[0].FindControl("yourUniqueCheckBoxID")).Checked=true;
                e.Item.CssClass="YourNewCssDecalredInStyleTag";
            }
        }
}
this example marks every item that aSpecialValue has been bound to it also change it's
CSS changes according to YourNewCssDecalredInStyleTag.
HtH.

--------------------------------------------
Mehdi.:)
 
Old August 23rd, 2004, 03:35 PM
Registered User
 
Join Date: Aug 2004
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you. Let me try your suggestion.

Thanks.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Display checkbox inside Table like structure in Vb remya1000 General .NET 0 May 15th, 2008 03:59 PM
checkbox in datagrid asad_prog VB.NET 0 November 25th, 2006 02:41 PM
Display every checkbox checked InsouciantCoquette Classic ASP Components 0 February 10th, 2006 04:02 AM
Checkbox in the datagrid sadermine VB Components 0 August 16th, 2005 10:36 PM
Display Checkbox if checked or not jmss66 Classic ASP Basics 6 January 23rd, 2004 11:19 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.