I tried to change the ConfirmText and ConfirmTitle for a GridButtonColumn from the back-end in the ItemDataBound event, but this only applies after a PostBack. So if on the first load of the page, I clicked the Delete button, it would delete without a confirmation window. However, after any PostBack, the confirmation window comes up successfully. Am I using the wrong event to change this?
01.
protected
void
rgPackagesHistory_ItemDataBound(
object
sender, GridItemEventArgs e)
02.
{
03.
if
(e.Item
is
GridDataItem)
04.
{
05.
((GridButtonColumn)rgPackagesHistory.MasterTableView.GetColumnSafe(
"column1abc"
)).ConfirmTitle = rxM.GetString(
"DeleteConfirmationTitle"
, cul);
06.
((GridButtonColumn)rgPackagesHistory.MasterTableView.GetColumnSafe(
"column1abc"
)).ConfirmText = rxM.GetString(
"DeleteConfirmation"
, cul);
07.
}
08.
}
6 Answers, 1 is accepted
You can try accessing the column on an earlier stage of the page life cycle, for example in the DataBinding event handler of the grid. Also, you can check the attached web site sample.
Regards,
Eyup
Telerik
I have been following this.
Your example is not very helpful. The goal is to dynamically update the RadConfrim message.
Can you please assist with a more relevant example?
Hello David,
You can modify the code suggested by Eyup to call a JavaScript function where you can assign whatever message you want:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridDataItem)
{
GridDataItem item = e.Item as GridDataItem;
ImageButton button = item["DeleteColumn"].Controls[0] as ImageButton;
string dataKeyID = item.GetDataKeyValue("OrderID").ToString();
string value = DataBinder.Eval(item.DataItem, "ShipCountry").ToString();
string time = DateTime.Now.ToLongTimeString();
string message = string.Format("Delete record <b>{0}</b> from <b>{1}</b> - {2}?",
dataKeyID, value, time);
//button.Attributes.Add("onclick", string.Format("if(!$find('{0}').confirm('{1}', event, 'Delete Record'))return false;",
// item.OwnerTableView.OwnerGrid.ClientID, message));
button.Attributes["onclick"] = "if(!deleteConfirmation('RadGrid1', event, 'Delete Record')) return false;";
}
}
<script type="text/javascript">
function deleteConfirmation(gridClientId, ev, originalMessage) {
var grid = $find(gridClientId)
var customMessage = "Do you want to delete??!?!";
return grid.confirm(customMessage, ev, gridClientId, 'Delete Record');
}
</script>
Regards,
Peter Milchev
Progress Telerik
Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.