aspxgridveiw是devexpress的一個(gè)grid控件,使用起來還不錯(cuò)。但是今天遇到一個(gè)問題,就是不能再 CustomButtonCallback 事件中使用response.write,因?yàn)镃ustomButtonCallback 事件是無刷新的,所以不支持,但是即使使用ScriptManager.RegisterClientScriptBlock(page, page.GetType(), "MyScript", myScript, true)也無濟(jì)于事,在網(wǎng)上查了很久,官方有個(gè)解決辦法,原文如下:
Hi Troy;
To provide this functionality you should throw an exception in the CustomButtonCallback event handler and process this exception in the CallbackError event handler. Here is the simple sample:
復(fù)制代碼 代碼如下:
protected void ASPxGridView1_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewCustomButtonCallbackEventArgs e)
{
throw new Exception("Here I am!");
}
復(fù)制代碼 代碼如下:
if (e.message == 'Here I am!')
{
clientErrorImage.SetVisible(true);
}
If this answer is incomplete or I misunderstood your requirements, please let me know.
Thanks
Kate.
但是實(shí)際測(cè)試中發(fā)現(xiàn)了問題, throw 的時(shí)候后臺(tái)直接拋出錯(cuò)誤了,,這個(gè)方法也行不通,再找。。。
最終還是在官網(wǎng)上找到了解決方案,原文地址,我的代碼如下:
復(fù)制代碼 代碼如下:
protected void ASPxGridView1_CustomButtonCallback(object sender, ASPxGridViewCustomButtonCallbackEventArgs e)
{
ASPxGridView view = sender as ASPxGridView;
if (e.ButtonID == "btnAudit")
{
int id = 0;
int.TryParse(view.GetRowValues(e.VisibleIndex, "id").ToString(), out id);
if (true)
{
view.JSProperties["cpErrorMsg"] = "審核成功!";
view.DataBind();
}
else
{
view.JSProperties["cpErrorMsg"] = "此單據(jù)已經(jīng)審核!";
}
}
}
復(fù)制代碼 代碼如下:
function EndCallBack(s, e) {
if (s.cpErrorMsg!="") {
alert(s.cpErrorMsg);
}
}
這里要注意:JSProperties的參數(shù)必須以小寫"cp"開頭。
測(cè)試通過,呵呵
您可能感興趣的文章:- 在GridView中LinkButton的屬性的應(yīng)用(如何不用選中就刪除這一行)
- 學(xué)習(xí)ExtJS(二) Button常用方法
- gridview中實(shí)現(xiàn)radiobutton的單選示例
- Flex4 DataGrid中如何嵌入RadioButton
- 獲取Gridview中ButtonField的text屬性
- gridview的buttonfield獲取該行的索引值(實(shí)例講解)
- EXT中單擊button按鈕grid添加一行(光標(biāo)位置可設(shè)置)的實(shí)例代碼