-2

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") %>' />
4

1 に答える 1

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") %>' 
/>
于 2012-12-05T11:44:49.250 に答える