API
Version 7.x > API > UniGrid OnExternalDataBound View modes: 
User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 4/16/2013 1:50:58 PM
   
UniGrid OnExternalDataBound
I've got a pretty simple unigrid setup and all the components are working as expected. I've now got a requirement to hide the "delete" image button and replace it with text. I'm able to hide the button, but not sure how I can return that button instance AND additional text. Do I need to add another action button? If so, how do I make it so its not a ImageButton?
<cms:UniGrid ID="gridBankAccounts" runat="server" ShowActionsMenu="true" RememberDefaultState="true" ShowActionsLabel="false" DisplayMode="Default" OnOnAction="gridBankAccounts_OnAction" OnOnExternalDataBound="gridBankAccounts_OnExternalDataBound">
<GridActions>
<ug:Action Name="deleteaction" Caption="Delete account" Icon="delete.png" ExternalSourceName="checkVisibility" CommandArgument="RS_ACCTCODE" Confirmation="$kt.confirmdelete.bankacct$" />
</GridActions>
<GridColumns>
<ug:Column Source="RS_ACCTDESC" Caption="Nickname" Wrap="false" AllowSorting="true" />
<ug:Column Source="RS_BANKNAME" Caption="Bank Name" Wrap="false" AllowSorting="true" />
<ug:Column Source="DisplayAccountType" Caption="Account Type" Wrap="false" AllowSorting="true" />
<ug:Column Source="RS_BANKACCT" Caption="Account Number" Wrap="false" AllowSorting="true" />
</GridColumns>
<GridOptions ShowSortDirection="true" DisplayPageSizeDropdown="false" />
</cms:UniGrid>
protected object gridBankAccounts_OnExternalDataBound(object sender, string sourceName, object parameter)
{
object param = null;
bool isDelete = false;

if (parameter is System.Web.UI.WebControls.GridViewRow)
{
param = ((System.Web.UI.WebControls.GridViewRow)parameter).DataItem;
}

isDelete = ValidationHelper.GetBoolean(GlobalHelper.IsYes(ValidationHelper.GetString(((System.Data.DataRowView)(param)).Row["RS_DELETE"], "Y")), true);

switch (sourceName)
{
case "checkVisibility": // setting button visibility based on if payments are pending against this account or not
ImageButton btn = (ImageButton)sender;
btn.Visible = isDelete;
// if isDelete, need to hide button and display label or text
return btn;
}
return parameter;
}

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 5/3/2013 7:13:50 AM
   
RE:UniGrid OnExternalDataBound
Hi,

I am not sure what exactly you mean by "how I can return that button instance AND additional text". Anyway, you could try, after you hide the button, to add another control to the collection of controls - it could be e.g. a literal or something similar to have the text displayed.

Best regards,
Juraj Ondrus

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 5/3/2013 10:33:24 AM
   
RE:UniGrid OnExternalDataBound
That's what I'm looking to do Juraj. I want to hide the "delete" button and return a new literal control. But what I've seen is the object being passed in is the image button. How do I access the control collection from this event?

User avatar
Kentico Support
Kentico Support
kentico_jurajo - 5/10/2013 2:13:45 AM
   
RE:UniGrid OnExternalDataBound
Hi,

The parent control of the image control should be available or, another option is to access the GridViewRow, there should be Cells property and this one has TableCell and in this TableCell are the controls too.

Best regards,
Juraj Ondrus