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 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.
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 think you can try this thing.
write a function in aspx as per that article.
something like Cell.Element.Child[0]....
and in your grid put a hidden column with value 0/1 to hide/show button.
in javascript check that cell and accordingly hide the button
and in your pageload do RegisterStartupScript("function name").
it should work for you.
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
if (canDelete())
e.Row.Cells.FromKey("DeleteButton").Column.Hidden = false;
else
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.
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