Dear All,
I am using Ultrawebgrid in my application.
I have added 3 ultragridcolumns, two are hyperlinks and one is button.
Depending on the condition hyperlink are visible for only the specified row and button aur visible for all the rows.
I just want to hide the button only for the specified row.
Can you please help me out.
Thanks,
Preet Sahani.
I have a similar problem. I've seen this mentioned as a bug in V6.2 but I can't get it working in V7.2 With the code below, the delete button still shows in all cells.
Am I doing something wrong here in the grid_InitializeRow event:
if (canDelete())
e.Row.Cells.FromKey("DeleteButton").Column.Hidden = false;
else
e.Row.Cells.FromKey("DeleteButton").Column.Hidden = true;
I think you just want to hide button for that perticuler row not whole grid.
if that is the case then you are doing wronge thing.
what you are doing is hiding whole column not just one cell by doing
I guess for the last row button should be showed and column hidden should be made false so it is showing column in whole grid.
try this thing. put a value in the last row for which you do have to hide button and it should hide whole column instead of just that thing. that will make confirm of what I am saying.
you can do this thing.
e.Row.Cells.FromKey("DeleteButton").Reset()
and then set stylesheet whatever is set for that row. because this will remove style also.
I think that is the only way that you Reset() it and then apply your style again.
If there is any other way I do not know of that.
The following article shows a way to use JavaScript to hide buttons (from a Button column type) in WebGrid on an individual basis:HOWTO: Hide buttons in a WebGrid using client-side JavaScript
I tried to use the javascript function in InitializeRowHandler but it doesnt work. It shows all the row with the button.
I even tried to use
e.Row.Cells.FromKey("DeleteButton").Style.CustomRules = "display:none;";
It hides all the button depending on the condition. But as there is no style applied it looks weird.
But when i add
e.Row.Cells.FromKey("DeleteButton").Style.CssStyle = "normal";
in the else section after
again all the button gets appeared.
When I check the Source of this page It shows Style as "Normal Button Normal."
It is appending the style instead of replacing it.
Preet.
preetsahani said:I tried to use the javascript function in InitializeRowHandler but it doesnt work.
The client-side InitializeRowHandler won't work for this purpose. This event is only raised when a row is added to the grid on the client. To get a reference to the rows present in the grid when the page is rendered, use the InitializeLayoutHandler instead and loop through all the rows present. This is different than the way the two corresponding server-side events work.
Changing the CssStyle property of the cell affects the whole cell, not just the button inside that cell, and we don't have a Style property that represents the button in a single cell of a button-type column. Setting a cell's Column.Hidden property would hide the entire column, not just the individual cell.
I don't know of any way to hide individual buttons in server-side code for a button-type column, other than using the approach defined in the Knowledge Base article I referenced in my previous post.
I ran across this post looking for an answer to this issue, and what I ended up solving this was flipping about the question and, instead of looking for a way to hide buttons, I looked for a way to add then dymically. It's pretty easy, just set your column type to "NotSet", and then set up a InitializeRow handler. Create the button in there along these lines:
row.Cells.FromKey("my_btn_column").Text = "<input type=\"button\" style=\"width:55px;\" value=\"Content Mgmt\" onclick=\"igtbl_colButtonClick(event,'Grid',null, igtbl_srcElement(event));\"/>";
Of course, it's easy to not create the button for a particular row, which is the whole point here.
ClickCellButton will still get called, and from there you can figure out which button was clicked via e.Cell.Column.Key, and if you have your DataKey property set up right then you will know which record to act upon.