Welcome Guest Search | Active Topics | Sign In | Register

Grid, checkbox column. I need to disable checkbox on one cell Options
pscagno
Posted: Wednesday, May 13, 2009 9:56:29 AM
Rank: Newbie
Groups: Member

Joined: 5/13/2009
Posts: 2
Hi, I have a grid with a checkbox column. I can't realize how to obtain the checkbox control inside the grid. I need to manage the state of that control in a cell, not for all the column. I saw that the cell has a property style, but if i put that as visibitlity:hidden or display:none, nothing happens.
Thanks in advance
Pablo
eo_support
Posted: Wednesday, May 13, 2009 12:11:05 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi,

You can do that by setting each cell's Style property. In order to use this property on the checkbox element inside the cell, you will need to use a child selector:

Code: HTML/ASPX
<style type="text/css">
.show_checkbox > input
{
    display:inline;
}
        
.hide_checkbox > input
{
    display:none;
}
</style>


Note the child selector "> input" instruct the browser to apply this class to any input element that is a child element of the given element (the Grid cell).

You can then use the following code to show/hide the checkbox inside the checkbox column:

Code: C#
//Show the checkbox for the first cell on the first row
Grid1.Items[0].Cells[0].Style = "show_checkbox";

//Hide the checkbox for the first cell on the second row
Grid1.Items[1].Cells[0].Style = "hide_checkbox";


Note the code assume the first column is a CheckBoxColumn.

Please let us know if this works for you.

Thanks!
pscagno
Posted: Wednesday, May 13, 2009 1:14:31 PM
Rank: Newbie
Groups: Member

Joined: 5/13/2009
Posts: 2
thanks
tim
Posted: Thursday, May 27, 2010 12:53:31 AM
Rank: Member
Groups: Member

Joined: 3/29/2009
Posts: 29
Hi,
I believe that what I am after is available by using this example, but I can't get it to work.
I want to conditionally display a checkbox in a row (depending on the value of another column in the SQL select).

It would seem that I could then do something like

if (display_field = 1) then
Grid1.Items[0].Cells[0].Style = "show_checkbox";
else
Grid1.Items[1].Cells[0].Style = "hide_checkbox";
end

which is perfect !

But, I must be missing something.
I have added the

<style type="text/css">
.show_checkbox > input
{
display:inline;
}

.hide_checkbox > input
{
display:none;
}
</style>


at the top of the HTML code where the style sheet code goes.
But this doesn't do anything.


I'm not sure what you mean when you say I need a you will need to use a "child selector"

I hope I am on track.

Thankyou.


eo_support
Posted: Thursday, May 27, 2010 8:46:12 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
tim wrote:
It would seem that I could then do something like

if (display_field = 1) then
Grid1.Items[0].Cells[0].Style = "show_checkbox";
else
Grid1.Items[1].Cells[0].Style = "hide_checkbox";
end
This is correct.

tim wrote:
at the top of the HTML code where the style sheet code goes.
But this doesn't do anything.
I would suggest you to try the code in a separate test page without your database first. That should work. You can then gradually add your code back in.


tim wrote:
I'm not sure what you mean when you say I need a you will need to use a "child selector"
The "show_checkbox > input" syntax is a child selector.

Thanks!
Slash
Posted: Friday, March 9, 2012 9:57:18 AM
Rank: Newbie
Groups: Member

Joined: 3/9/2012
Posts: 4
Hi all,

i tried this and it is working perfectly. It is difficult for me to understanding styles because i am not a web developer...lol

But i have just one doubt:
- DataGridView in Windows Forms has an event called: RowsAdded and we can use it to change cells each time a new row is inserted.

with EO:Grid, i didn't found such kind of event, so i write the code bellow inside an event: PreRender:

protected void Grid1_PreRender(object sender, EventArgs e)
{
int colIni = Grid1.Items[0].Cells["P5"].Column.Index;

for (int i = 0; i < Grid1.Items.Count; i++)
{
if (Grid1.Items[i].Cells["majorstyle"].Value != null && Grid1.Items[i].Cells["majorstyle"].Value.ToString() != "")
{
for (int col = 0; col < 6; col++)
{
Grid1.Items[i].Cells[colIni+col].Style = "hide_checkbox";
}
}
}
}

Is this right or there is a better solution to change cells style?

Another question is: to hide a cell, i need to write the style directly to code or can i use Grid Editor?

I noticed that the property: StyleSetIDField does not retain its content when i use Grid Editor, i need to write this property through code in Page_Load, is this a bug or i am doing something wrong?

thanks!!
eo_support
Posted: Friday, March 9, 2012 11:27:33 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Hi Slash,

For ASP.NET there are ".aspx" and "code behind". You can set any property either way. The Grid Editor is just a way for you to modify ".aspx". You do not have to use it at all. The primary purpose of the Grid Editor is to allow you to instantlly modify and preview styles. So it does not copy all properties.

Your code of setting Style is fine. You can also set your styles in your data source and then use StyleSetIDField to automatically set Style property based on your data. That will save you some code.

Thanks!
Slash
Posted: Friday, March 9, 2012 12:31:30 PM
Rank: Newbie
Groups: Member

Joined: 3/9/2012
Posts: 4
Ok, i stoped to use Grid Editor and write directly in code pane. Now i am able to do all things i want.
I used StyleSetIDField and forgot my code, like you said.

Thank you!
eo_support
Posted: Friday, March 9, 2012 1:05:59 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
You are very welcome. Please feel free to let us know if you have any more questions.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.