This is a migrated thread and some comments may be shown as answers.

GridCheckBoxColumn returns  

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
SonicImaging
Top achievements
Rank 1
SonicImaging asked on 05 Jan 2009, 03:20 PM
Hi,  I have a GridCheckBoxColumn that im creating in codebehind with the DataField and Unique Name called active

I need to get its value in ItemDataBound so I can change the text of the Edit column based on this value. So this is what im doing

        if (e.Item is GridDataItem)
        {
            GridDataItem dataItem = e.Item as GridDataItem;
            if (dataItem["active"].Text == "False")
            {
                   // Change edit column text here
            }
            else
            {
                  // Change edit column text here
            }
        }

All my other columns in DataItem return the proper values but all the checkbox column returns is    The visible and display are set to true and the CheckBoxColumn is visible.   Is this the correct way to do this?   ive tried searching the docs and forums for GridCheckBoxColumn but it either returns no results or I get a server error.

Thoughts?
-Keith


1 Answer, 1 is accepted

Sort by
0
SonicImaging
Top achievements
Rank 1
answered on 05 Jan 2009, 03:45 PM
Hi,  I figured out another way,   it seems that the forum and docs search is messed up.  When I tried to search on GridCheckBoxColumn I either got no results found or a server error.   Is there a problem with the searching on the site?  I just tried it again and it seems to be working now.

I just did this

if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = e.Item as GridDataItem; 
            CheckBox chkbx = (CheckBox)dataItem["active"].Controls[0]; 
 
            if (chkbx.Checked) 
            { 
                // This record is active show the normal edit button on this row 
                // and set the row color to black 
                TableCell editCell = ((GridDataItem)e.Item)["editColumn"]; 
                LinkButton LinkButton1 = (LinkButton)editCell.Controls[0]; 
                LinkButton1.Visible = true
                LinkButton1.Text = "Edit"
                dataItem.ForeColor = System.Drawing.ColorTranslator.FromHtml("#000000"); 
            } 
            else 
            { 
                // This record is not active change the text to Revert the row color to grey 
                // and the CommandArg to Revert| To parse the cmdarg in the OnEditCommand event 
                TableCell editCell = ((GridDataItem)e.Item)["editColumn"]; 
                LinkButton LinkButton1 = (LinkButton)editCell.Controls[0]; 
                LinkButton1.Visible = true
                LinkButton1.Text = "Revert"
                LinkButton1.CommandArgument = "Revert|" + dataItem["id"].Text; 
                dataItem.ForeColor = System.Drawing.ColorTranslator.FromHtml("#C0C0C0"); 
                dataItem.Visible = true
            } 
        } 


Thanks
-Keith



Tags
Grid
Asked by
SonicImaging
Top achievements
Rank 1
Answers by
SonicImaging
Top achievements
Rank 1
Share this question
or