2012-12-05 35 views
-2

在Gridview中,我正在使用圖像按鈕,希望根據字段中的值啓用。我的部分代碼是..想要啓用圖像按鈕基於Gridview字段中的值

<asp:ImageButton ID="btn_delete" **Enabled='<%# Eval("fld_status").ToString()=="1" ? "False" : "True" %>**' runat="server" ToolTip="Delete" OnClientClick="return confirm('Important Alert : Do you delete this item ?')" CommandName="del" CommandArgument='<%#Bind("fld_id") %>' /> 
+2

而你的問題是什麼? –

+0

如果fld_status = 1意味着,我想爲Image Button設置Enable =「False」。 – Bharathi

+0

您是否嘗試過在您的GridView的DataItemBounded事件中執行此操作? –

回答

4
通過 RowDataBound

(我喜歡):

protected void gridview1_RowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     DataRowView row = (DataRowView)e.Row.DataItem; 
     int status = (int)row["fld_status"]; 
     Button btn_delete = (Button) e.Row.FindControl("btn_delete"); 
     btn_delete.Enabled = status != 1; 
    } 
} 

從ASPX:

<asp:ImageButton ID="btn_delete" runat="server" 
    Enabled='<%# ((int)Eval("fld_status") !=1) ? true : false %>' 
    ToolTip="Delete" OnClientClick="return confirm('Important Alert : Do you delete this item ?')" CommandName="del" CommandArgument='<%#Bind("fld_id") %>' 
/> 
+0

第二個工作嗎? - _服務器標籤格式不正確 – codingbiz

+0

aspx:CS0019:運算符'!='不能應用於'object'和'int'類型的操作數 – Bharathi

+0

@codingbiz:更正了,這就是我總是使用RowDataBound的原因。 –

相關問題