Telerik GridButtonColumn的条件确认消息

时间:2014-07-28 21:29:42

标签: c# asp.net telerik

我是这些技术的新手。

我有radgrid个列表数据集以及与每个数据集关联的报告。用户可以单击GridButtonColumn中的删除图标以从数据库中删除报告。

如果用户删除与数据集关联的上一个报告,我还想删除该数据集。但如果是这种情况,我想抛出不同的确认信息。

逻辑: 点击删除>查询数据库>如果这是与数据集关联的最后一个报告,则抛出消息A,否则抛出消息B

ASPX

<telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="Delete"
 ButtonType="ImageButton" ImageUrl="~/Icons/delete.png" AutoPostBackOnFilter="true"
 ConfirmTitle="Delete" ConfirmDialogType="Classic"  
 ConfirmText="Are you sure want to delete the selected report?" />

ASPX.CS

    protected void RadGridUser_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == RadGrid.DeleteCommandName)
    {
        GridDataItem dataItem = e.Item as GridDataItem;
        int reportID = Convert.ToInt32(dataItem["reportID"].Text);
        int datasetID = Convert.ToInt32(dataItem["datasetID"].Text);

        string countQry = "select * from reportTable where datasetID=" + datasetID;
        DataSet dsCount = DBUtils.ExecuteDataset(countQry);

        //delete data if this is the only report left for the data set
        if (dsCount.Tables[0].Rows.Count <= 1)
        {  //set ConfirmText = "Deleting this report will also delete the data set. Do you want to delete the data set?"
           //DELETE DATA
        }
        //set ConfirmText = "Are you sure you want to delete the selected report?"
        //DELETE REPORT
    }
  }

有没有办法查询数据库并根据查询结果使用此GridButonColumn更改ConfirmText?

1 个答案:

答案 0 :(得分:1)

除了FeliceM提供的线索,我认为答案是http://www.telerik.com/forums/dynamically-set-confirmtext-on-gridbuttoncolumn),您可以使用此处所述的自定义确认:http://www.telerik.com/help/aspnet-ajax/window-using-radconfirm-in-server-code.html

内置确认在服务器事件之前触发,因此您需要确保在客户端上加载页面时有正确的消息,否则,如果您需要确认来自服务器,请使用方法I联的。