Want to enable image button based on the value in the Gridview Field

后端 未结 1 937
夕颜
夕颜 2021-01-29 12:31

In Gridview i am using image button that Want to enable based on the value in the Field. My Partial Code is ..



        
相关标签:
1条回答
  • 2021-01-29 12:44

    via RowDataBound (which i prefer):

    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; 
        }
    }
    

    from 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 讨论(0)
提交回复
热议问题